DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Public Member Functions | Protected Member Functions | List of all members
Deveel.Data.Linq.ExpressionVisitor Class Reference
Inheritance diagram for Deveel.Data.Linq.ExpressionVisitor:
Deveel.Data.Linq.Evaluator.Nominator Deveel.Data.Linq.Evaluator.SubtreeEvaluator Deveel.Data.Linq.ExpressionTreeModifier Deveel.Data.Linq.InnermostWhereFinder Deveel.Data.Linq.QueryBuilder

Public Member Functions

virtual Expression Visit (Expression exp)
 

Protected Member Functions

 ExpressionVisitor ()
 
virtual MemberBinding VisitBinding (MemberBinding binding)
 
virtual ElementInit VisitElementInitializer (ElementInit initializer)
 
virtual Expression VisitUnary (UnaryExpression u)
 
virtual Expression VisitBinary (BinaryExpression b)
 
virtual Expression VisitTypeIs (TypeBinaryExpression b)
 
virtual Expression VisitConstant (ConstantExpression c)
 
virtual Expression VisitConditional (ConditionalExpression c)
 
virtual Expression VisitParameter (ParameterExpression p)
 
virtual Expression VisitMemberAccess (MemberExpression m)
 
virtual Expression VisitMethodCall (MethodCallExpression m)
 
virtual ReadOnlyCollection< Expression > VisitExpressionList (ReadOnlyCollection< Expression > original)
 
virtual MemberAssignment VisitMemberAssignment (MemberAssignment assignment)
 
virtual MemberMemberBinding VisitMemberMemberBinding (MemberMemberBinding binding)
 
virtual MemberListBinding VisitMemberListBinding (MemberListBinding binding)
 
virtual IEnumerable< MemberBinding > VisitBindingList (ReadOnlyCollection< MemberBinding > original)
 
virtual IEnumerable< ElementInit > VisitElementInitializerList (ReadOnlyCollection< ElementInit > original)
 
virtual Expression VisitLambda (LambdaExpression lambda)
 
virtual NewExpression VisitNew (NewExpression nex)
 
virtual Expression VisitMemberInit (MemberInitExpression init)
 
virtual Expression VisitListInit (ListInitExpression init)
 
virtual Expression VisitNewArray (NewArrayExpression na)
 
virtual Expression VisitInvocation (InvocationExpression iv)
 

Detailed Description

Definition at line 24 of file ExpressionVisitor.cs.

Constructor & Destructor Documentation

Deveel.Data.Linq.ExpressionVisitor.ExpressionVisitor ( )
inlineprotected

Definition at line 25 of file ExpressionVisitor.cs.

25  {
26  }

Member Function Documentation

virtual Expression Deveel.Data.Linq.ExpressionVisitor.Visit ( Expression  exp)
inlinevirtual

Reimplemented in Deveel.Data.Linq.Evaluator.Nominator, and Deveel.Data.Linq.Evaluator.SubtreeEvaluator.

Definition at line 28 of file ExpressionVisitor.cs.

28  {
29  if (exp == null)
30  return exp;
31  switch (exp.NodeType) {
32  case ExpressionType.Negate:
33  case ExpressionType.NegateChecked:
34  case ExpressionType.Not:
35  case ExpressionType.Convert:
36  case ExpressionType.ConvertChecked:
37  case ExpressionType.ArrayLength:
38  case ExpressionType.Quote:
39  case ExpressionType.TypeAs:
40  return this.VisitUnary((UnaryExpression)exp);
41  case ExpressionType.Add:
42  case ExpressionType.AddChecked:
43  case ExpressionType.Subtract:
44  case ExpressionType.SubtractChecked:
45  case ExpressionType.Multiply:
46  case ExpressionType.MultiplyChecked:
47  case ExpressionType.Divide:
48  case ExpressionType.Modulo:
49  case ExpressionType.And:
50  case ExpressionType.AndAlso:
51  case ExpressionType.Or:
52  case ExpressionType.OrElse:
53  case ExpressionType.LessThan:
54  case ExpressionType.LessThanOrEqual:
55  case ExpressionType.GreaterThan:
56  case ExpressionType.GreaterThanOrEqual:
57  case ExpressionType.Equal:
58  case ExpressionType.NotEqual:
59  case ExpressionType.Coalesce:
60  case ExpressionType.ArrayIndex:
61  case ExpressionType.RightShift:
62  case ExpressionType.LeftShift:
63  case ExpressionType.ExclusiveOr:
64  return VisitBinary((BinaryExpression)exp);
65  case ExpressionType.TypeIs:
66  return VisitTypeIs((TypeBinaryExpression)exp);
67  case ExpressionType.Conditional:
68  return VisitConditional((ConditionalExpression)exp);
69  case ExpressionType.Constant:
70  return VisitConstant((ConstantExpression)exp);
71  case ExpressionType.Parameter:
72  return VisitParameter((ParameterExpression)exp);
73  case ExpressionType.MemberAccess:
74  return VisitMemberAccess((MemberExpression)exp);
75  case ExpressionType.Call:
76  return VisitMethodCall((MethodCallExpression)exp);
77  case ExpressionType.Lambda:
78  return VisitLambda((LambdaExpression)exp);
79  case ExpressionType.New:
80  return VisitNew((NewExpression)exp);
81  case ExpressionType.NewArrayInit:
82  case ExpressionType.NewArrayBounds:
83  return VisitNewArray((NewArrayExpression)exp);
84  case ExpressionType.Invoke:
85  return VisitInvocation((InvocationExpression)exp);
86  case ExpressionType.MemberInit:
87  return VisitMemberInit((MemberInitExpression)exp);
88  case ExpressionType.ListInit:
89  return VisitListInit((ListInitExpression)exp);
90  default:
91  throw new Exception(string.Format("Unhandled expression type: '{0}'", exp.NodeType));
92  }
93  }
virtual Expression VisitTypeIs(TypeBinaryExpression b)
virtual Expression VisitParameter(ParameterExpression p)
virtual Expression VisitBinary(BinaryExpression b)
virtual Expression VisitNewArray(NewArrayExpression na)
virtual Expression VisitListInit(ListInitExpression init)
virtual Expression VisitMethodCall(MethodCallExpression m)
virtual Expression VisitMemberInit(MemberInitExpression init)
virtual Expression VisitConditional(ConditionalExpression c)
virtual NewExpression VisitNew(NewExpression nex)
virtual Expression VisitInvocation(InvocationExpression iv)
virtual Expression VisitMemberAccess(MemberExpression m)
virtual Expression VisitUnary(UnaryExpression u)
virtual Expression VisitLambda(LambdaExpression lambda)
virtual Expression VisitConstant(ConstantExpression c)
virtual Expression Deveel.Data.Linq.ExpressionVisitor.VisitBinary ( BinaryExpression  b)
inlineprotectedvirtual

Reimplemented in Deveel.Data.Linq.QueryBuilder.

Definition at line 124 of file ExpressionVisitor.cs.

124  {
125  Expression left = Visit(b.Left);
126  Expression right = Visit(b.Right);
127  Expression conversion = Visit(b.Conversion);
128  if (left != b.Left || right != b.Right || conversion != b.Conversion) {
129  if (b.NodeType == ExpressionType.Coalesce && b.Conversion != null)
130  return Expression.Coalesce(left, right, conversion as LambdaExpression);
131 
132  return Expression.MakeBinary(b.NodeType, left, right, b.IsLiftedToNull, b.Method);
133  }
134  return b;
135  }
virtual Expression Visit(Expression exp)
virtual MemberBinding Deveel.Data.Linq.ExpressionVisitor.VisitBinding ( MemberBinding  binding)
inlineprotectedvirtual

Definition at line 95 of file ExpressionVisitor.cs.

95  {
96  switch (binding.BindingType) {
97  case MemberBindingType.Assignment:
98  return VisitMemberAssignment((MemberAssignment)binding);
99  case MemberBindingType.MemberBinding:
100  return VisitMemberMemberBinding((MemberMemberBinding)binding);
101  case MemberBindingType.ListBinding:
102  return VisitMemberListBinding((MemberListBinding)binding);
103  default:
104  throw new Exception(string.Format("Unhandled binding type '{0}'", binding.BindingType));
105  }
106  }
virtual MemberAssignment VisitMemberAssignment(MemberAssignment assignment)
virtual MemberMemberBinding VisitMemberMemberBinding(MemberMemberBinding binding)
virtual MemberListBinding VisitMemberListBinding(MemberListBinding binding)
virtual IEnumerable<MemberBinding> Deveel.Data.Linq.ExpressionVisitor.VisitBindingList ( ReadOnlyCollection< MemberBinding >  original)
inlineprotectedvirtual

Definition at line 224 of file ExpressionVisitor.cs.

224  {
225  List<MemberBinding> list = null;
226  for (int i = 0, n = original.Count; i < n; i++) {
227  MemberBinding b = this.VisitBinding(original[i]);
228  if (list != null) {
229  list.Add(b);
230  } else if (b != original[i]) {
231  list = new List<MemberBinding>(n);
232  for (int j = 0; j < i; j++) {
233  list.Add(original[j]);
234  }
235  list.Add(b);
236  }
237  }
238  if (list != null)
239  return list;
240  return original;
241  }
virtual MemberBinding VisitBinding(MemberBinding binding)
virtual Expression Deveel.Data.Linq.ExpressionVisitor.VisitConditional ( ConditionalExpression  c)
inlineprotectedvirtual

Definition at line 149 of file ExpressionVisitor.cs.

149  {
150  Expression test = Visit(c.Test);
151  Expression ifTrue = Visit(c.IfTrue);
152  Expression ifFalse = Visit(c.IfFalse);
153  if (test != c.Test || ifTrue != c.IfTrue || ifFalse != c.IfFalse) {
154  return Expression.Condition(test, ifTrue, ifFalse);
155  }
156  return c;
157  }
virtual Expression Visit(Expression exp)
virtual Expression Deveel.Data.Linq.ExpressionVisitor.VisitConstant ( ConstantExpression  c)
inlineprotectedvirtual

Reimplemented in Deveel.Data.Linq.ExpressionTreeModifier.

Definition at line 145 of file ExpressionVisitor.cs.

145  {
146  return c;
147  }
virtual ElementInit Deveel.Data.Linq.ExpressionVisitor.VisitElementInitializer ( ElementInit  initializer)
inlineprotectedvirtual

Definition at line 108 of file ExpressionVisitor.cs.

108  {
109  ReadOnlyCollection<Expression> arguments = VisitExpressionList(initializer.Arguments);
110  if (arguments != initializer.Arguments) {
111  return Expression.ElementInit(initializer.AddMethod, arguments);
112  }
113  return initializer;
114  }
virtual ReadOnlyCollection< Expression > VisitExpressionList(ReadOnlyCollection< Expression > original)
virtual IEnumerable<ElementInit> Deveel.Data.Linq.ExpressionVisitor.VisitElementInitializerList ( ReadOnlyCollection< ElementInit >  original)
inlineprotectedvirtual

Definition at line 243 of file ExpressionVisitor.cs.

243  {
244  List<ElementInit> list = null;
245  for (int i = 0, n = original.Count; i < n; i++) {
246  ElementInit init = this.VisitElementInitializer(original[i]);
247  if (list != null) {
248  list.Add(init);
249  } else if (init != original[i]) {
250  list = new List<ElementInit>(n);
251  for (int j = 0; j < i; j++) {
252  list.Add(original[j]);
253  }
254  list.Add(init);
255  }
256  }
257  if (list != null)
258  return list;
259  return original;
260  }
virtual ElementInit VisitElementInitializer(ElementInit initializer)
virtual ReadOnlyCollection<Expression> Deveel.Data.Linq.ExpressionVisitor.VisitExpressionList ( ReadOnlyCollection< Expression >  original)
inlineprotectedvirtual

Definition at line 180 of file ExpressionVisitor.cs.

180  {
181  List<Expression> list = null;
182  for (int i = 0, n = original.Count; i < n; i++) {
183  Expression p = this.Visit(original[i]);
184  if (list != null) {
185  list.Add(p);
186  } else if (p != original[i]) {
187  list = new List<Expression>(n);
188  for (int j = 0; j < i; j++) {
189  list.Add(original[j]);
190  }
191  list.Add(p);
192  }
193  }
194  if (list != null) {
195  return list.AsReadOnly();
196  }
197  return original;
198  }
virtual Expression Visit(Expression exp)
virtual Expression Deveel.Data.Linq.ExpressionVisitor.VisitInvocation ( InvocationExpression  iv)
inlineprotectedvirtual

Definition at line 311 of file ExpressionVisitor.cs.

311  {
312  IEnumerable<Expression> args = this.VisitExpressionList(iv.Arguments);
313  Expression expr = this.Visit(iv.Expression);
314  if (args != iv.Arguments || expr != iv.Expression) {
315  return Expression.Invoke(expr, args);
316  }
317  return iv;
318  }
virtual Expression Visit(Expression exp)
virtual ReadOnlyCollection< Expression > VisitExpressionList(ReadOnlyCollection< Expression > original)
virtual Expression Deveel.Data.Linq.ExpressionVisitor.VisitLambda ( LambdaExpression  lambda)
inlineprotectedvirtual

Definition at line 262 of file ExpressionVisitor.cs.

262  {
263  Expression body = this.Visit(lambda.Body);
264  if (body != lambda.Body) {
265  return Expression.Lambda(lambda.Type, body, lambda.Parameters);
266  }
267  return lambda;
268  }
virtual Expression Visit(Expression exp)
virtual Expression Deveel.Data.Linq.ExpressionVisitor.VisitListInit ( ListInitExpression  init)
inlineprotectedvirtual

Definition at line 290 of file ExpressionVisitor.cs.

290  {
291  NewExpression n = this.VisitNew(init.NewExpression);
292  IEnumerable<ElementInit> initializers = this.VisitElementInitializerList(init.Initializers);
293  if (n != init.NewExpression || initializers != init.Initializers) {
294  return Expression.ListInit(n, initializers);
295  }
296  return init;
297  }
virtual IEnumerable< ElementInit > VisitElementInitializerList(ReadOnlyCollection< ElementInit > original)
virtual NewExpression VisitNew(NewExpression nex)
virtual Expression Deveel.Data.Linq.ExpressionVisitor.VisitMemberAccess ( MemberExpression  m)
inlineprotectedvirtual

Definition at line 163 of file ExpressionVisitor.cs.

163  {
164  Expression exp = this.Visit(m.Expression);
165  if (exp != m.Expression) {
166  return Expression.MakeMemberAccess(exp, m.Member);
167  }
168  return m;
169  }
virtual Expression Visit(Expression exp)
virtual MemberAssignment Deveel.Data.Linq.ExpressionVisitor.VisitMemberAssignment ( MemberAssignment  assignment)
inlineprotectedvirtual

Reimplemented in Deveel.Data.Linq.QueryBuilder.

Definition at line 200 of file ExpressionVisitor.cs.

200  {
201  Expression e = this.Visit(assignment.Expression);
202  if (e != assignment.Expression) {
203  return Expression.Bind(assignment.Member, e);
204  }
205  return assignment;
206  }
virtual Expression Visit(Expression exp)
virtual Expression Deveel.Data.Linq.ExpressionVisitor.VisitMemberInit ( MemberInitExpression  init)
inlineprotectedvirtual

Definition at line 281 of file ExpressionVisitor.cs.

281  {
282  NewExpression n = this.VisitNew(init.NewExpression);
283  IEnumerable<MemberBinding> bindings = this.VisitBindingList(init.Bindings);
284  if (n != init.NewExpression || bindings != init.Bindings) {
285  return Expression.MemberInit(n, bindings);
286  }
287  return init;
288  }
virtual IEnumerable< MemberBinding > VisitBindingList(ReadOnlyCollection< MemberBinding > original)
virtual NewExpression VisitNew(NewExpression nex)
virtual MemberListBinding Deveel.Data.Linq.ExpressionVisitor.VisitMemberListBinding ( MemberListBinding  binding)
inlineprotectedvirtual

Definition at line 216 of file ExpressionVisitor.cs.

216  {
217  IEnumerable<ElementInit> initializers = this.VisitElementInitializerList(binding.Initializers);
218  if (initializers != binding.Initializers) {
219  return Expression.ListBind(binding.Member, initializers);
220  }
221  return binding;
222  }
virtual IEnumerable< ElementInit > VisitElementInitializerList(ReadOnlyCollection< ElementInit > original)
virtual MemberMemberBinding Deveel.Data.Linq.ExpressionVisitor.VisitMemberMemberBinding ( MemberMemberBinding  binding)
inlineprotectedvirtual

Definition at line 208 of file ExpressionVisitor.cs.

208  {
209  IEnumerable<MemberBinding> bindings = this.VisitBindingList(binding.Bindings);
210  if (bindings != binding.Bindings) {
211  return Expression.MemberBind(binding.Member, bindings);
212  }
213  return binding;
214  }
virtual IEnumerable< MemberBinding > VisitBindingList(ReadOnlyCollection< MemberBinding > original)
virtual Expression Deveel.Data.Linq.ExpressionVisitor.VisitMethodCall ( MethodCallExpression  m)
inlineprotectedvirtual

Reimplemented in Deveel.Data.Linq.InnermostWhereFinder.

Definition at line 171 of file ExpressionVisitor.cs.

171  {
172  Expression obj = this.Visit(m.Object);
173  IEnumerable<Expression> args = this.VisitExpressionList(m.Arguments);
174  if (obj != m.Object || args != m.Arguments) {
175  return Expression.Call(obj, m.Method, args);
176  }
177  return m;
178  }
virtual Expression Visit(Expression exp)
virtual ReadOnlyCollection< Expression > VisitExpressionList(ReadOnlyCollection< Expression > original)
virtual NewExpression Deveel.Data.Linq.ExpressionVisitor.VisitNew ( NewExpression  nex)
inlineprotectedvirtual

Definition at line 270 of file ExpressionVisitor.cs.

270  {
271  IEnumerable<Expression> args = this.VisitExpressionList(nex.Arguments);
272  if (args != nex.Arguments) {
273  if (nex.Members != null)
274  return Expression.New(nex.Constructor, args, nex.Members);
275  else
276  return Expression.New(nex.Constructor, args);
277  }
278  return nex;
279  }
virtual ReadOnlyCollection< Expression > VisitExpressionList(ReadOnlyCollection< Expression > original)
virtual Expression Deveel.Data.Linq.ExpressionVisitor.VisitNewArray ( NewArrayExpression  na)
inlineprotectedvirtual

Definition at line 299 of file ExpressionVisitor.cs.

299  {
300  IEnumerable<Expression> exprs = this.VisitExpressionList(na.Expressions);
301  if (exprs != na.Expressions) {
302  if (na.NodeType == ExpressionType.NewArrayInit) {
303  return Expression.NewArrayInit(na.Type.GetElementType(), exprs);
304  } else {
305  return Expression.NewArrayBounds(na.Type.GetElementType(), exprs);
306  }
307  }
308  return na;
309  }
virtual ReadOnlyCollection< Expression > VisitExpressionList(ReadOnlyCollection< Expression > original)
virtual Expression Deveel.Data.Linq.ExpressionVisitor.VisitParameter ( ParameterExpression  p)
inlineprotectedvirtual

Definition at line 159 of file ExpressionVisitor.cs.

159  {
160  return p;
161  }
virtual Expression Deveel.Data.Linq.ExpressionVisitor.VisitTypeIs ( TypeBinaryExpression  b)
inlineprotectedvirtual

Definition at line 137 of file ExpressionVisitor.cs.

137  {
138  Expression expr = Visit(b.Expression);
139  if (expr != b.Expression) {
140  return Expression.TypeIs(expr, b.TypeOperand);
141  }
142  return b;
143  }
virtual Expression Visit(Expression exp)
virtual Expression Deveel.Data.Linq.ExpressionVisitor.VisitUnary ( UnaryExpression  u)
inlineprotectedvirtual

Definition at line 116 of file ExpressionVisitor.cs.

116  {
117  Expression operand = Visit(u.Operand);
118  if (operand != u.Operand) {
119  return Expression.MakeUnary(u.NodeType, operand, u.Type, u.Method);
120  }
121  return u;
122  }
virtual Expression Visit(Expression exp)

The documentation for this class was generated from the following file: