Updates referencesource to .NET 4.7
[mono-project.git] / mcs / class / referencesource / System.Data.Entity / System / Data / Query / InternalTrees / ScalarOps.cs
blobc9c554ad622be35c02c64a1f03325163a2b1ae5e
1 //---------------------------------------------------------------------
2 // <copyright file="ScalarOps.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
4 // </copyright>
5 //
6 // @owner Microsoft
7 // @backupOwner Microsoft
8 //---------------------------------------------------------------------
10 using System;
11 using System.Collections.Generic;
12 using System.Globalization;
13 using System.Diagnostics;
14 using System.Data.Common;
15 using System.Data.Metadata.Edm;
17 namespace System.Data.Query.InternalTrees
19 #region Constants
21 /// <summary>
22 /// Base class for all constant Ops
23 /// </summary>
24 internal abstract class ConstantBaseOp : ScalarOp
26 #region private state
27 private readonly object m_value;
28 #endregion
30 #region constructors
31 protected ConstantBaseOp(OpType opType, TypeUsage type, object value)
32 : base(opType, type)
34 m_value = value;
37 /// <summary>
38 /// Constructor overload for rules
39 /// </summary>
40 /// <param name="opType"></param>
41 protected ConstantBaseOp(OpType opType)
42 : base(opType)
45 #endregion
47 #region public properties and methods
48 /// <summary>
49 /// Get the constant value
50 /// </summary>
51 internal virtual Object Value { get { return m_value; } }
53 /// <summary>
54 /// 0 children
55 /// </summary>
56 internal override int Arity { get { return 0; } }
58 /// <summary>
59 /// Two CostantBaseOps are equivalent if they are of the same
60 /// derived type and have the same type and value.
61 /// </summary>
62 /// <param name="other">the other Op</param>
63 /// <returns>true, if these are equivalent (not a strict equality test)</returns>
64 internal override bool IsEquivalent(Op other)
66 ConstantBaseOp otherConstant = other as ConstantBaseOp;
67 return
68 otherConstant != null &&
69 this.OpType == other.OpType &&
70 otherConstant.Type.EdmEquals(this.Type) &&
71 ((otherConstant.Value == null && this.Value == null) || otherConstant.Value.Equals(this.Value));
73 #endregion
76 /// <summary>
77 /// Represents an external constant
78 /// </summary>
79 internal sealed class ConstantOp : ConstantBaseOp
81 #region constructors
82 internal ConstantOp(TypeUsage type, object value)
83 : base(OpType.Constant, type, value)
85 Debug.Assert(value != null, "ConstantOp with a null value?");
87 private ConstantOp() : base(OpType.Constant) { }
88 #endregion
90 #region public methods
91 /// <summary>
92 /// Pattern for transformation rules
93 /// </summary>
94 internal static readonly ConstantOp Pattern = new ConstantOp();
96 /// <summary>
97 /// Visitor pattern method
98 /// </summary>
99 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
100 /// <param name="n">The Node that references this Op</param>
101 [DebuggerNonUserCode]
102 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
104 /// <summary>
105 /// Visitor pattern method for visitors with a return value
106 /// </summary>
107 /// <param name="v">The visitor</param>
108 /// <param name="n">The node in question</param>
109 /// <returns>An instance of TResultType</returns>
110 [DebuggerNonUserCode]
111 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
113 #endregion
116 /// <summary>
117 /// Represents null constants
118 /// </summary>
119 internal sealed class NullOp : ConstantBaseOp
121 #region constructors
122 internal NullOp(TypeUsage type)
123 : base(OpType.Null, type, null)
126 private NullOp() : base(OpType.Null) { }
127 #endregion
129 #region public apis
131 /// <summary>
132 /// Pattern for transformation rules
133 /// </summary>
134 internal static readonly NullOp Pattern = new NullOp();
136 /// <summary>
137 /// Visitor pattern method
138 /// </summary>
139 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
140 /// <param name="n">The Node that references this Op</param>
141 [DebuggerNonUserCode]
142 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
144 /// <summary>
145 /// Visitor pattern method for visitors with a return value
146 /// </summary>
147 /// <param name="v">The visitor</param>
148 /// <param name="n">The node in question</param>
149 /// <returns>An instance of TResultType</returns>
150 [DebuggerNonUserCode]
151 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
153 #endregion
156 /// <summary>
157 /// Represents internally generated constants
158 /// </summary>
159 internal sealed class InternalConstantOp : ConstantBaseOp
161 #region constructors
162 internal InternalConstantOp(TypeUsage type, object value)
163 : base(OpType.InternalConstant, type, value)
165 Debug.Assert(value != null, "InternalConstantOp with a null value?");
167 private InternalConstantOp() : base(OpType.InternalConstant) { }
168 #endregion
170 #region public apis
172 /// <summary>
173 /// Pattern for transformation rules
174 /// </summary>
175 internal static readonly InternalConstantOp Pattern = new InternalConstantOp();
177 /// <summary>
178 /// Visitor pattern method
179 /// </summary>
180 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
181 /// <param name="n">The Node that references this Op</param>
182 [DebuggerNonUserCode]
183 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
185 /// <summary>
186 /// Visitor pattern method for visitors with a return value
187 /// </summary>
188 /// <param name="v">The visitor</param>
189 /// <param name="n">The node in question</param>
190 /// <returns>An instance of TResultType</returns>
191 [DebuggerNonUserCode]
192 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
194 #endregion
197 /// <summary>
198 /// Represents an internally generated constant that is used to serve as a null sentinel,
199 /// i.e. to be checked whether it is null.
200 /// </summary>
201 internal sealed class NullSentinelOp : ConstantBaseOp
203 #region constructors
204 internal NullSentinelOp(TypeUsage type, object value)
205 : base(OpType.NullSentinel, type, value)
208 private NullSentinelOp() : base(OpType.NullSentinel) { }
209 #endregion
211 #region public apis
212 /// <summary>
213 /// Pattern for transformation rules
214 /// </summary>
215 internal static readonly NullSentinelOp Pattern = new NullSentinelOp();
217 /// <summary>
218 /// Visitor pattern method
219 /// </summary>
220 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
221 /// <param name="n">The Node that references this Op</param>
222 [DebuggerNonUserCode]
223 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
225 /// <summary>
226 /// Visitor pattern method for visitors with a return value
227 /// </summary>
228 /// <param name="v">The visitor</param>
229 /// <param name="n">The node in question</param>
230 /// <returns>An instance of TResultType</returns>
231 [DebuggerNonUserCode]
232 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
234 #endregion
237 /// <summary>
238 /// Represents a constant predicate (with a value of either true or false)
239 /// </summary>
240 internal sealed class ConstantPredicateOp : ConstantBaseOp
242 #region constructors
243 internal ConstantPredicateOp(TypeUsage type, bool value)
244 : base(OpType.ConstantPredicate, type, value)
247 private ConstantPredicateOp()
248 : base(OpType.ConstantPredicate)
250 #endregion
252 #region public methods
253 /// <summary>
254 /// Pattern for transformation rules
255 /// </summary>
256 internal static readonly ConstantPredicateOp Pattern = new ConstantPredicateOp();
258 /// <summary>
259 /// Value of the constant predicate
260 /// </summary>
261 internal new bool Value { get { return (bool)base.Value; } }
263 /// <summary>
264 /// Is this the true predicate
265 /// </summary>
266 internal bool IsTrue { get { return this.Value; } }
268 /// <summary>
269 /// Is this the 'false' predicate
270 /// </summary>
271 internal bool IsFalse { get { return this.Value == false; } }
273 /// <summary>
274 /// Visitor pattern method
275 /// </summary>
276 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
277 /// <param name="n">The Node that references this Op</param>
278 [DebuggerNonUserCode]
279 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
281 /// <summary>
282 /// Visitor pattern method for visitors with a return value
283 /// </summary>
284 /// <param name="v">The visitor</param>
285 /// <param name="n">The node in question</param>
286 /// <returns>An instance of TResultType</returns>
287 [DebuggerNonUserCode]
288 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
290 #endregion
293 #endregion
295 /// <summary>
296 /// A reference to an existing variable
297 /// </summary>
298 internal sealed class VarRefOp : ScalarOp
300 #region private state
301 private Var m_var;
302 #endregion
304 #region constructors
305 internal VarRefOp(Var v) : base(OpType.VarRef, v.Type)
307 m_var = v;
309 private VarRefOp() : base(OpType.VarRef) { }
310 #endregion
312 #region public methods
313 /// <summary>
314 /// Singleton used for pattern matching
315 /// </summary>
316 internal static readonly VarRefOp Pattern = new VarRefOp();
318 /// <summary>
319 /// 0 children
320 /// </summary>
321 internal override int Arity { get { return 0; } }
323 /// <summary>
324 /// Two VarRefOps are equivalent, if they reference the same Var
325 /// </summary>
326 /// <param name="other">the other Op</param>
327 /// <returns>true, if these are equivalent</returns>
328 internal override bool IsEquivalent(Op other)
330 VarRefOp otherVarRef = other as VarRefOp;
331 return (otherVarRef != null && otherVarRef.Var.Equals(this.Var));
334 /// <summary>
335 /// The Var that this Op is referencing
336 /// </summary>
337 internal Var Var { get { return m_var; } }
339 /// <summary>
340 /// Visitor pattern method
341 /// </summary>
342 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
343 /// <param name="n">The Node that references this Op</param>
344 [DebuggerNonUserCode]
345 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
347 /// <summary>
348 /// Visitor pattern method for visitors with a return value
349 /// </summary>
350 /// <param name="v">The visitor</param>
351 /// <param name="n">The node in question</param>
352 /// <returns>An instance of TResultType</returns>
353 [DebuggerNonUserCode]
354 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
355 #endregion
358 /// <summary>
359 /// Represents an arbitrary function call
360 /// </summary>
361 internal sealed class FunctionOp : ScalarOp
363 #region private state
364 private EdmFunction m_function;
365 #endregion
367 #region constructors
368 internal FunctionOp(EdmFunction function)
369 : base(OpType.Function, function.ReturnParameter.TypeUsage)
371 m_function = function;
373 private FunctionOp() : base(OpType.Function) { }
374 #endregion
376 #region public methods
377 /// <summary>
378 /// Singleton instance used for patterns in transformation rules
379 /// </summary>
380 internal static readonly FunctionOp Pattern = new FunctionOp();
382 /// <summary>
383 /// The function that's being invoked
384 /// </summary>
385 internal EdmFunction Function { get { return m_function; } }
387 /// <summary>
388 /// Two FunctionOps are equivalent if they reference the same EdmFunction
389 /// </summary>
390 /// <param name="other">the other Op</param>
391 /// <returns>true, if these are equivalent</returns>
392 internal override bool IsEquivalent(Op other)
394 FunctionOp otherFunctionOp = other as FunctionOp;
395 return (otherFunctionOp != null && otherFunctionOp.Function.EdmEquals(this.Function));
398 /// <summary>
399 /// Visitor pattern method
400 /// </summary>
401 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
402 /// <param name="n">The Node that references this Op</param>
403 [DebuggerNonUserCode]
404 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
406 /// <summary>
407 /// Visitor pattern method for visitors with a return value
408 /// </summary>
409 /// <param name="v">The visitor</param>
410 /// <param name="n">The node in question</param>
411 /// <returns>An instance of TResultType</returns>
412 [DebuggerNonUserCode]
413 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
414 #endregion
417 /// <summary>
418 /// Represents a property access
419 /// </summary>
420 internal sealed class PropertyOp : ScalarOp
422 #region private state
423 private EdmMember m_property;
424 #endregion
426 #region constructors
427 internal PropertyOp(TypeUsage type, EdmMember property)
428 : base(OpType.Property, type)
430 Debug.Assert((property is EdmProperty) || (property is RelationshipEndMember) || (property is NavigationProperty), "Unexpected EdmMember type");
431 m_property = property;
433 private PropertyOp() : base(OpType.Property) { }
434 #endregion
436 #region public methods
437 /// <summary>
438 /// Used for patterns in transformation rules
439 /// </summary>
440 internal static readonly PropertyOp Pattern = new PropertyOp();
442 /// <summary>
443 /// 1 child - the instance
444 /// </summary>
445 internal override int Arity { get { return 1; } }
447 /// <summary>
448 /// The property metadata
449 /// </summary>
450 internal EdmMember PropertyInfo { get { return m_property; } }
452 /// <summary>
453 /// Visitor pattern method
454 /// </summary>
455 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
456 /// <param name="n">The Node that references this Op</param>
457 [DebuggerNonUserCode]
458 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
460 /// <summary>
461 /// Visitor pattern method for visitors with a return value
462 /// </summary>
463 /// <param name="v">The visitor</param>
464 /// <param name="n">The node in question</param>
465 /// <returns>An instance of TResultType</returns>
466 [DebuggerNonUserCode]
467 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
468 #endregion
471 /// <summary>
472 /// Represents a TREAT AS operation
473 /// </summary>
474 internal sealed class TreatOp : ScalarOp
476 #region private state
477 private bool m_isFake;
478 #endregion
480 #region constructors
481 internal TreatOp(TypeUsage type, bool isFake)
482 : base(OpType.Treat, type)
484 m_isFake = isFake;
486 private TreatOp() : base(OpType.Treat) { }
487 #endregion
489 #region public methods
490 /// <summary>
491 /// Used as patterns in transformation rules
492 /// </summary>
493 internal static readonly TreatOp Pattern = new TreatOp();
495 /// <summary>
496 /// 1 child - instance
497 /// </summary>
498 internal override int Arity { get { return 1; } }
500 /// <summary>
501 /// Is this a "fake" treat?
502 /// </summary>
503 internal bool IsFakeTreat { get { return m_isFake; } }
505 /// <summary>
506 /// Visitor pattern method
507 /// </summary>
508 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
509 /// <param name="n">The Node that references this Op</param>
510 [DebuggerNonUserCode]
511 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
513 /// <summary>
514 /// Visitor pattern method for visitors with a return value
515 /// </summary>
516 /// <param name="v">The visitor</param>
517 /// <param name="n">The node in question</param>
518 /// <returns>An instance of TResultType</returns>
519 [DebuggerNonUserCode]
520 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
521 #endregion
524 /// <summary>
525 /// An IS OF operation
526 /// </summary>
527 internal sealed class IsOfOp : ScalarOp
529 #region private state
530 private TypeUsage m_isOfType;
531 private bool m_isOfOnly;
532 #endregion
534 #region constructors
535 internal IsOfOp(TypeUsage isOfType, bool isOfOnly, TypeUsage type)
536 : base(OpType.IsOf, type)
538 m_isOfType = isOfType;
539 m_isOfOnly = isOfOnly;
541 private IsOfOp() : base(OpType.IsOf) { }
542 #endregion
544 #region public methods
545 /// <summary>
546 /// Pattern used for transformation rules
547 /// </summary>
548 internal static readonly IsOfOp Pattern = new IsOfOp();
550 /// <summary>
551 /// 1 child - instance
552 /// </summary>
553 internal override int Arity { get { return 1; } }
555 /// <summary>
556 /// The type being checked for
557 /// </summary>
558 internal TypeUsage IsOfType { get { return m_isOfType; } }
560 internal bool IsOfOnly { get { return m_isOfOnly; } }
562 /// <summary>
563 /// Visitor pattern method
564 /// </summary>
565 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
566 /// <param name="n">The Node that references this Op</param>
567 [DebuggerNonUserCode]
568 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
570 /// <summary>
571 /// Visitor pattern method for visitors with a return value
572 /// </summary>
573 /// <param name="v">The visitor</param>
574 /// <param name="n">The node in question</param>
575 /// <returns>An instance of TResultType</returns>
576 [DebuggerNonUserCode]
577 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
578 #endregion
581 /// <summary>
582 /// Cast operation. Convert a type instance into an instance of another type
583 /// </summary>
584 internal sealed class CastOp : ScalarOp
586 #region constructors
587 internal CastOp(TypeUsage type) : base(OpType.Cast, type) { }
588 private CastOp() : base(OpType.Cast) { }
589 #endregion
591 #region public methods
592 /// <summary>
593 /// Pattern for transformation rules
594 /// </summary>
595 internal static readonly CastOp Pattern = new CastOp();
597 /// <summary>
598 /// 1 child - instance
599 /// </summary>
600 internal override int Arity { get { return 1; } }
602 /// <summary>
603 /// Visitor pattern method
604 /// </summary>
605 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
606 /// <param name="n">The Node that references this Op</param>
607 [DebuggerNonUserCode]
608 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
610 /// <summary>
611 /// Visitor pattern method for visitors with a return value
612 /// </summary>
613 /// <param name="v">The visitor</param>
614 /// <param name="n">The node in question</param>
615 /// <returns>An instance of TResultType</returns>
616 [DebuggerNonUserCode]
617 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
618 #endregion
621 /// <summary>
622 /// An internal cast operation. (Softly) Convert a type instance into an instance of another type
623 ///
624 /// This Op is intended to capture "promotion" semantics. (ie) int16 promotes to an int32; Customer promotes to Person
625 /// etc. This Op is intended to shield the PlanCompiler from having to reason about
626 /// the promotion semantics; and is intended to make the query tree very
627 /// explicit
628 ///
629 /// </summary>
630 internal sealed class SoftCastOp : ScalarOp
632 #region constructors
633 internal SoftCastOp(TypeUsage type) : base(OpType.SoftCast, type) { }
634 private SoftCastOp() : base(OpType.SoftCast) { }
635 #endregion
637 #region public methods
638 /// <summary>
639 /// Pattern for transformation rules
640 /// </summary>
641 internal static readonly SoftCastOp Pattern = new SoftCastOp();
643 /// <summary>
644 /// 1 child - input expression
645 /// </summary>
646 internal override int Arity { get { return 1; } }
648 /// <summary>
649 /// Visitor pattern method
650 /// </summary>
651 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
652 /// <param name="n">The Node that references this Op</param>
653 [DebuggerNonUserCode]
654 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
656 /// <summary>
657 /// Visitor pattern method for visitors with a return value
658 /// </summary>
659 /// <param name="v">The visitor</param>
660 /// <param name="n">The node in question</param>
661 /// <returns>An instance of TResultType</returns>
662 [DebuggerNonUserCode]
663 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
664 #endregion
667 /// <summary>
668 /// Represents a comparision operation (LT, GT etc.)
669 /// </summary>
670 internal sealed class ComparisonOp : ScalarOp
672 #region constructors
673 internal ComparisonOp(OpType opType, TypeUsage type)
674 : base(opType, type)
677 private ComparisonOp(OpType opType) : base(opType) { }
678 #endregion
680 #region public methods
681 /// <summary>
682 /// Patterns for use in transformation rules
683 /// </summary>
684 internal static readonly ComparisonOp PatternEq = new ComparisonOp(OpType.EQ);
686 /// <summary>
687 /// 2 children - left, right
688 /// </summary>
689 internal override int Arity { get { return 2; } }
691 /// <summary>
692 /// Visitor pattern method
693 /// </summary>
694 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
695 /// <param name="n">The Node that references this Op</param>
696 [DebuggerNonUserCode]
697 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
699 /// <summary>
700 /// Visitor pattern method for visitors with a return value
701 /// </summary>
702 /// <param name="v">The visitor</param>
703 /// <param name="n">The node in question</param>
704 /// <returns>An instance of TResultType</returns>
705 [DebuggerNonUserCode]
706 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
707 #endregion
710 /// <summary>
711 /// Represents a string comparison operation
712 /// </summary>
713 internal sealed class LikeOp : ScalarOp
715 #region constructors
716 internal LikeOp(TypeUsage boolType)
717 : base(OpType.Like, boolType) { }
718 private LikeOp() : base(OpType.Like) { }
719 #endregion
721 #region public surface
722 /// <summary>
723 /// Pattern for use in transformation rules
724 /// </summary>
725 internal static readonly LikeOp Pattern = new LikeOp();
727 /// <summary>
728 /// 3 children - string, pattern , escape
729 /// </summary>
730 internal override int Arity { get { return 3; } }
732 /// <summary>
733 /// Visitor pattern method
734 /// </summary>
735 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
736 /// <param name="n">The Node that references this Op</param>
737 [DebuggerNonUserCode]
738 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
740 /// <summary>
741 /// Visitor pattern method for visitors with a return value
742 /// </summary>
743 /// <param name="v">The visitor</param>
744 /// <param name="n">The node in question</param>
745 /// <returns>An instance of TResultType</returns>
746 [DebuggerNonUserCode]
747 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
748 #endregion
751 /// <summary>
752 /// Represents a conditional operation - and,or,not, is null
753 /// A little hacky - since it represents and/or/not as optypes - could I not
754 /// have done the same with the comparison operators?
755 /// </summary>
756 internal sealed class ConditionalOp : ScalarOp
758 #region constructors
759 internal ConditionalOp(OpType optype, TypeUsage type) : base(optype, type)
762 private ConditionalOp(OpType opType) : base(opType) { }
763 #endregion
765 #region public methods
766 /// <summary>
767 /// Patterns for use in transformation rules
768 /// </summary>
769 internal static readonly ConditionalOp PatternAnd = new ConditionalOp(OpType.And);
770 internal static readonly ConditionalOp PatternOr = new ConditionalOp(OpType.Or);
771 internal static readonly ConditionalOp PatternNot = new ConditionalOp(OpType.Not);
772 internal static readonly ConditionalOp PatternIsNull = new ConditionalOp(OpType.IsNull);
774 /// <summary>
775 /// Visitor pattern method
776 /// </summary>
777 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
778 /// <param name="n">The Node that references this Op</param>
779 [DebuggerNonUserCode]
780 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
782 /// <summary>
783 /// Visitor pattern method for visitors with a return value
784 /// </summary>
785 /// <param name="v">The visitor</param>
786 /// <param name="n">The node in question</param>
787 /// <returns>An instance of TResultType</returns>
788 [DebuggerNonUserCode]
789 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
790 #endregion
793 /// <summary>
794 /// ANSI switched Case expression.
795 /// </summary>
796 internal sealed class CaseOp : ScalarOp
798 #region constructors
799 internal CaseOp(TypeUsage type) : base(OpType.Case, type) { }
800 private CaseOp() : base(OpType.Case) { }
801 #endregion
803 #region public methods
804 /// <summary>
805 /// Pattern for use in transformation rules
806 /// </summary>
807 internal static readonly CaseOp Pattern = new CaseOp();
809 /// <summary>
810 /// Visitor pattern method
811 /// </summary>
812 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
813 /// <param name="n">The Node that references this Op</param>
814 [DebuggerNonUserCode]
815 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
817 /// <summary>
818 /// Visitor pattern method for visitors with a return value
819 /// </summary>
820 /// <param name="v">The visitor</param>
821 /// <param name="n">The node in question</param>
822 /// <returns>An instance of TResultType</returns>
823 [DebuggerNonUserCode]
824 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
825 #endregion
828 /// <summary>
829 /// Basic Aggregates
830 /// </summary>
831 internal sealed class AggregateOp : ScalarOp
833 #region private state
834 private EdmFunction m_aggFunc;
835 private bool m_distinctAgg;
836 #endregion
838 #region constructors
839 internal AggregateOp(EdmFunction aggFunc, bool distinctAgg)
840 : base(OpType.Aggregate, aggFunc.ReturnParameter.TypeUsage)
842 m_aggFunc = aggFunc;
843 m_distinctAgg = distinctAgg;
845 private AggregateOp() : base(OpType.Aggregate) { }
846 #endregion
848 #region public methods
849 /// <summary>
850 /// Pattern for transformation rules
851 /// </summary>
852 internal static readonly AggregateOp Pattern = new AggregateOp();
854 /// <summary>
855 /// The Aggregate function's metadata
856 /// </summary>
857 internal EdmFunction AggFunc { get { return m_aggFunc; } }
859 /// <summary>
860 /// Is this a "distinct" aggregate
861 /// </summary>
862 internal bool IsDistinctAggregate { get { return m_distinctAgg; } }
864 /// <summary>
865 /// Yes; this is an aggregate
866 /// </summary>
867 internal override bool IsAggregateOp {get{return true;}}
869 /// <summary>
870 /// Visitor pattern method
871 /// </summary>
872 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
873 /// <param name="n">The Node that references this Op</param>
874 [DebuggerNonUserCode]
875 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
877 /// <summary>
878 /// Visitor pattern method for visitors with a return value
879 /// </summary>
880 /// <param name="v">The visitor</param>
881 /// <param name="n">The node in question</param>
882 /// <returns>An instance of TResultType</returns>
883 [DebuggerNonUserCode]
884 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
885 #endregion
888 /// <summary>
889 /// Represents an arbitrary nest operation - can be used anywhere
890 /// </summary>
891 internal sealed class CollectOp : ScalarOp
893 #region constructors
894 internal CollectOp(TypeUsage type) : base(OpType.Collect, type) { }
895 private CollectOp() : base(OpType.Collect) { }
896 #endregion
898 #region public methods
899 /// <summary>
900 /// Pattern for use in transformation rules
901 /// </summary>
902 internal static readonly CollectOp Pattern = new CollectOp();
904 /// <summary>
905 /// 1 child - instance
906 /// </summary>
907 internal override int Arity { get { return 1; } }
909 /// <summary>
910 /// Visitor pattern method
911 /// </summary>
912 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
913 /// <param name="n">The Node that references this Op</param>
914 [DebuggerNonUserCode]
915 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
917 /// <summary>
918 /// Visitor pattern method for visitors with a return value
919 /// </summary>
920 /// <param name="v">The visitor</param>
921 /// <param name="n">The node in question</param>
922 /// <returns>An instance of TResultType</returns>
923 [DebuggerNonUserCode]
924 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
925 #endregion
928 /// <summary>
929 /// Almost identical to a PropertyOp - the only difference being that we're dealing with an
930 /// "extended" property (a rel property) this time
931 /// </summary>
932 internal sealed class RelPropertyOp : ScalarOp
934 #region private state
935 private readonly RelProperty m_property;
936 #endregion
938 #region constructors
939 private RelPropertyOp() : base(OpType.RelProperty) { }
941 internal RelPropertyOp(TypeUsage type, RelProperty property)
942 : base(OpType.RelProperty, type)
944 m_property = property;
946 #endregion
948 #region public APIs
949 /// <summary>
950 /// Pattern for transformation rules
951 /// </summary>
952 internal static readonly RelPropertyOp Pattern = new RelPropertyOp();
954 /// <summary>
955 /// 1 child - the entity instance
956 /// </summary>
957 internal override int Arity { get { return 1; } }
959 /// <summary>
960 /// Get the property metadata
961 /// </summary>
962 public RelProperty PropertyInfo { get { return m_property; } }
964 /// <summary>
965 /// Visitor pattern method
966 /// </summary>
967 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
968 /// <param name="n">The Node that references this Op</param>
969 [DebuggerNonUserCode]
970 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
972 /// <summary>
973 /// Visitor pattern method for visitors with a return value
974 /// </summary>
975 /// <param name="v">The visitor</param>
976 /// <param name="n">The node in question</param>
977 /// <returns>An instance of TResultType</returns>
978 [DebuggerNonUserCode]
979 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
981 #endregion
984 /// <summary>
985 /// Base class for DiscriminatedNewEntityOp and NewEntityOp
986 /// </summary>
987 internal abstract class NewEntityBaseOp : ScalarOp
989 #region private state
990 private readonly bool m_scoped;
991 private readonly EntitySet m_entitySet;
992 private readonly List<RelProperty> m_relProperties; // list of relationship properties for which we have values
993 #endregion
995 #region constructors
996 internal NewEntityBaseOp(OpType opType, TypeUsage type, bool scoped, EntitySet entitySet, List<RelProperty> relProperties)
997 : base(opType, type)
999 Debug.Assert(scoped || entitySet == null, "entitySet cann't be set of constructor isn't scoped");
1000 Debug.Assert(relProperties != null, "expected non-null list of rel-properties");
1001 m_scoped = scoped;
1002 m_entitySet = entitySet;
1003 m_relProperties = relProperties;
1006 protected NewEntityBaseOp(OpType opType) : base(opType) { }
1007 #endregion
1009 #region public APIs
1010 /// <summary>
1011 /// True if the entity constructor is scoped to a particular entity set or null (scoped as "unscoped").
1012 /// False if the scope is not yet known. Scope is determined in PreProcessor.
1013 /// </summary>
1014 internal bool Scoped { get { return m_scoped; } }
1016 /// <summary>
1017 /// Get the entityset (if any) associated with this constructor
1018 /// </summary>
1019 internal EntitySet EntitySet { get { return m_entitySet; } }
1021 /// <summary>
1022 /// get the list of relationship properties (if any) specified for this constructor
1023 /// </summary>
1024 internal List<RelProperty> RelationshipProperties { get { return m_relProperties; } }
1025 #endregion
1028 /// <summary>
1029 /// A new entity instance constructor
1030 /// </summary>
1031 internal sealed class NewEntityOp : NewEntityBaseOp
1033 #region constructors
1034 private NewEntityOp() : base(OpType.NewEntity) { }
1036 internal NewEntityOp(TypeUsage type, List<RelProperty> relProperties, bool scoped, EntitySet entitySet)
1037 : base(OpType.NewEntity, type, scoped, entitySet, relProperties)
1040 #endregion
1042 #region public methods
1043 /// <summary>
1044 /// Pattern for transformation rules
1045 /// </summary>
1046 internal static readonly NewEntityOp Pattern = new NewEntityOp();
1048 /// <summary>
1049 /// Visitor pattern method
1050 /// </summary>
1051 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
1052 /// <param name="n">The Node that references this Op</param>
1053 [DebuggerNonUserCode]
1054 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
1056 /// <summary>
1057 /// Visitor pattern method for visitors with a return value
1058 /// </summary>
1059 /// <param name="v">The visitor</param>
1060 /// <param name="n">The node in question</param>
1061 /// <returns>An instance of TResultType</returns>
1062 [DebuggerNonUserCode]
1063 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
1064 #endregion
1067 /// <summary>
1068 /// A new instance creation
1069 /// </summary>
1070 internal sealed class NewInstanceOp : ScalarOp
1072 #region constructors
1073 internal NewInstanceOp(TypeUsage type) : base(OpType.NewInstance, type)
1075 Debug.Assert(!type.EdmType.Abstract, "cannot create new instance of abstract type");
1076 Debug.Assert(!TypeSemantics.IsEntityType(type), "cannot use this Op for entity construction");
1078 private NewInstanceOp() : base(OpType.NewInstance) { }
1079 #endregion
1081 #region public methods
1082 /// <summary>
1083 /// Pattern for transformation rules
1084 /// </summary>
1085 internal static readonly NewInstanceOp Pattern = new NewInstanceOp();
1087 /// <summary>
1088 /// Visitor pattern method
1089 /// </summary>
1090 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
1091 /// <param name="n">The Node that references this Op</param>
1092 [DebuggerNonUserCode]
1093 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
1095 /// <summary>
1096 /// Visitor pattern method for visitors with a return value
1097 /// </summary>
1098 /// <param name="v">The visitor</param>
1099 /// <param name="n">The node in question</param>
1100 /// <returns>An instance of TResultType</returns>
1101 [DebuggerNonUserCode]
1102 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
1103 #endregion
1106 /// <summary>
1107 /// Polymorphic new instance creation (takes all properties of all types in the hierarchy + discriminator)
1108 /// </summary>
1109 internal sealed class DiscriminatedNewEntityOp : NewEntityBaseOp
1111 #region Private state
1112 private readonly ExplicitDiscriminatorMap m_discriminatorMap;
1113 #endregion
1115 #region Constructors
1116 internal DiscriminatedNewEntityOp(TypeUsage type, ExplicitDiscriminatorMap discriminatorMap,
1117 EntitySet entitySet, List<RelProperty> relProperties)
1118 : base(OpType.DiscriminatedNewEntity, type, true, entitySet, relProperties)
1120 Debug.Assert(null != discriminatorMap, "null discriminator map");
1121 m_discriminatorMap = discriminatorMap;
1123 private DiscriminatedNewEntityOp() : base(OpType.DiscriminatedNewEntity) { }
1124 #endregion
1126 #region "Public" members
1127 internal static readonly DiscriminatedNewEntityOp Pattern = new DiscriminatedNewEntityOp();
1129 /// <summary>
1130 /// Gets discriminator and type information used in construction of type.
1131 /// </summary>
1132 internal ExplicitDiscriminatorMap DiscriminatorMap
1134 get { return m_discriminatorMap; }
1137 [DebuggerNonUserCode]
1138 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
1140 [DebuggerNonUserCode]
1141 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
1142 #endregion
1145 /// <summary>
1146 /// Represents a new record constructor
1147 /// </summary>
1148 internal sealed class NewRecordOp : ScalarOp
1150 #region private state
1151 private List<EdmProperty> m_fields; // list of fields with specified values
1152 #endregion
1154 #region constructors
1155 /// <summary>
1156 /// Basic constructor. All fields have a value specified
1157 /// </summary>
1158 /// <param name="type"></param>
1159 internal NewRecordOp(TypeUsage type) : base(OpType.NewRecord, type)
1161 m_fields = new List<EdmProperty>(TypeHelpers.GetEdmType<RowType>(type).Properties);
1163 /// <summary>
1164 /// Alternate form of the constructor. Only some fields have a value specified
1165 /// The arguments to the corresponding Node are exactly 1-1 with the fields
1166 /// described here.
1167 /// The missing fields are considered to be "null"
1168 /// </summary>
1169 /// <param name="type"></param>
1170 /// <param name="fields"></param>
1171 internal NewRecordOp(TypeUsage type, List<EdmProperty> fields)
1172 : base(OpType.NewRecord, type)
1174 #if DEBUG
1175 foreach (EdmProperty p in fields)
1177 Debug.Assert(Object.ReferenceEquals(p.DeclaringType, this.Type.EdmType));
1179 #endif
1180 m_fields = fields;
1182 private NewRecordOp() : base(OpType.NewRecord) { }
1183 #endregion
1185 #region public methods
1186 /// <summary>
1187 /// Pattern for transformation rules
1188 /// </summary>
1189 internal static readonly NewRecordOp Pattern = new NewRecordOp();
1191 /// <summary>
1192 /// Determine if a value has been provided for the specified field.
1193 /// Returns the position of this field (ie) the specific argument in the Node's
1194 /// children. If no value has been provided for this field, then simply
1195 /// return false
1196 /// </summary>
1197 /// <param name="field"></param>
1198 /// <param name="fieldPosition"></param>
1199 /// <returns></returns>
1200 internal bool GetFieldPosition(EdmProperty field, out int fieldPosition)
1202 Debug.Assert(Object.ReferenceEquals(field.DeclaringType, this.Type.EdmType),
1203 "attempt to get invalid field from this record type");
1205 fieldPosition = 0;
1206 for (int i = 0; i < m_fields.Count; i++)
1208 if (m_fields[i] == field)
1210 fieldPosition = i;
1211 return true;
1214 return false;
1217 /// <summary>
1218 /// List of all properties that have values specified
1219 /// </summary>
1220 internal List<EdmProperty> Properties { get { return m_fields; } }
1222 /// <summary>
1223 /// Visitor pattern method
1224 /// </summary>
1225 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
1226 /// <param name="n">The Node that references this Op</param>
1227 [DebuggerNonUserCode]
1228 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
1230 /// <summary>
1231 /// Visitor pattern method for visitors with a return value
1232 /// </summary>
1233 /// <param name="v">The visitor</param>
1234 /// <param name="n">The node in question</param>
1235 /// <returns>An instance of TResultType</returns>
1236 [DebuggerNonUserCode]
1237 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
1238 #endregion
1241 internal sealed class NewMultisetOp : ScalarOp
1243 #region constructors
1244 internal NewMultisetOp(TypeUsage type) : base(OpType.NewMultiset, type) { }
1245 private NewMultisetOp() : base(OpType.NewMultiset) { }
1246 #endregion
1248 #region public methods
1249 /// <summary>
1250 /// Pattern for transformation rules
1251 /// </summary>
1252 internal static readonly NewMultisetOp Pattern = new NewMultisetOp();
1254 /// <summary>
1255 /// Visitor pattern method
1256 /// </summary>
1257 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
1258 /// <param name="n">The Node that references this Op</param>
1259 [DebuggerNonUserCode]
1260 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
1262 /// <summary>
1263 /// Visitor pattern method for visitors with a return value
1264 /// </summary>
1265 /// <param name="v">The visitor</param>
1266 /// <param name="n">The node in question</param>
1267 /// <returns>An instance of TResultType</returns>
1268 [DebuggerNonUserCode]
1269 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
1270 #endregion
1273 /// <summary>
1274 /// Represents arithmetic operators - Plus,Minus,Multiply,Divide,Modulo,UnaryMinus
1275 /// </summary>
1276 internal sealed class ArithmeticOp : ScalarOp
1278 #region constructors
1279 internal ArithmeticOp(OpType opType, TypeUsage type)
1280 : base(opType, type) { }
1281 #endregion
1283 #region public methods
1285 /// <summary>
1286 /// Visitor pattern method
1287 /// </summary>
1288 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
1289 /// <param name="n">The Node that references this Op</param>
1290 [DebuggerNonUserCode]
1291 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
1293 /// <summary>
1294 /// Visitor pattern method for visitors with a return value
1295 /// </summary>
1296 /// <param name="v">The visitor</param>
1297 /// <param name="n">The node in question</param>
1298 /// <returns>An instance of TResultType</returns>
1299 [DebuggerNonUserCode]
1300 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
1301 #endregion
1304 /// <summary>
1306 /// </summary>
1307 internal sealed class RefOp : ScalarOp
1309 #region private state
1310 private EntitySet m_entitySet;
1311 #endregion
1313 #region constructors
1314 internal RefOp(EntitySet entitySet, TypeUsage type)
1315 : base(OpType.Ref, type)
1317 m_entitySet = entitySet;
1319 private RefOp() : base(OpType.Ref) { }
1320 #endregion
1322 #region public methods
1323 /// <summary>
1324 /// Pattern for transformation rules
1325 /// </summary>
1326 internal static readonly RefOp Pattern = new RefOp();
1328 /// <summary>
1329 /// 1 child - key
1330 /// </summary>
1331 internal override int Arity { get { return 1; } }
1333 /// <summary>
1334 /// The EntitySet to which the reference refers
1335 /// </summary>
1336 internal EntitySet EntitySet { get { return m_entitySet; } }
1338 /// <summary>
1339 /// Visitor pattern method
1340 /// </summary>
1341 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
1342 /// <param name="n">The Node that references this Op</param>
1343 [DebuggerNonUserCode]
1344 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
1346 /// <summary>
1347 /// Visitor pattern method for visitors with a return value
1348 /// </summary>
1349 /// <param name="v">The visitor</param>
1350 /// <param name="n">The node in question</param>
1351 /// <returns>An instance of TResultType</returns>
1352 [DebuggerNonUserCode]
1353 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
1354 #endregion
1357 /// <summary>
1358 /// Represents an EXISTS subquery?
1359 /// </summary>
1360 internal sealed class ExistsOp : ScalarOp
1362 #region constructors
1363 internal ExistsOp(TypeUsage type)
1364 : base(OpType.Exists, type)
1367 private ExistsOp() : base(OpType.Exists) { }
1368 #endregion
1370 #region public methods
1371 /// <summary>
1372 /// Pattern for transformation rules
1373 /// </summary>
1374 internal static readonly ExistsOp Pattern = new ExistsOp();
1376 /// <summary>
1377 /// 1 child - collection input
1378 /// </summary>
1379 internal override int Arity { get { return 1; } }
1381 /// <summary>
1382 /// Visitor pattern method
1383 /// </summary>
1384 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
1385 /// <param name="n">The Node that references this Op</param>
1386 [DebuggerNonUserCode]
1387 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
1389 /// <summary>
1390 /// Visitor pattern method for visitors with a return value
1391 /// </summary>
1392 /// <param name="v">The visitor</param>
1393 /// <param name="n">The node in question</param>
1394 /// <returns>An instance of TResultType</returns>
1395 [DebuggerNonUserCode]
1396 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
1397 #endregion
1400 /// <summary>
1401 /// Represents an Element() op - extracts the scalar value from a collection
1402 /// </summary>
1403 internal sealed class ElementOp : ScalarOp
1405 #region constructors
1406 internal ElementOp(TypeUsage type) : base(OpType.Element, type) { }
1407 private ElementOp() : base(OpType.Element) { }
1408 #endregion
1410 #region public methods
1411 /// <summary>
1412 /// Pattern for transformation rules
1413 /// </summary>
1414 internal static readonly ElementOp Pattern = new ElementOp();
1416 /// <summary>
1417 /// 1 child - collection instance
1418 /// </summary>
1419 internal override int Arity { get { return 1; } }
1421 /// <summary>
1422 /// Visitor pattern method
1423 /// </summary>
1424 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
1425 /// <param name="n">The Node that references this Op</param>
1426 [DebuggerNonUserCode]
1427 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
1429 /// <summary>
1430 /// Visitor pattern method for visitors with a return value
1431 /// </summary>
1432 /// <param name="v">The visitor</param>
1433 /// <param name="n">The node in question</param>
1434 /// <returns>An instance of TResultType</returns>
1435 [DebuggerNonUserCode]
1436 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
1437 #endregion
1440 /// <summary>
1441 /// extracts the key from a ref
1442 /// </summary>
1443 internal sealed class GetRefKeyOp : ScalarOp
1445 #region constructors
1446 internal GetRefKeyOp(TypeUsage type) : base(OpType.GetRefKey, type) { }
1447 private GetRefKeyOp() : base(OpType.GetRefKey) { }
1448 #endregion
1450 #region public methods
1451 /// <summary>
1452 /// Pattern for transformation rules
1453 /// </summary>
1454 internal static readonly GetRefKeyOp Pattern = new GetRefKeyOp();
1456 /// <summary>
1457 /// 1 child - ref instance
1458 /// </summary>
1459 internal override int Arity { get { return 1; } }
1461 /// <summary>
1462 /// Visitor pattern method
1463 /// </summary>
1464 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
1465 /// <param name="n">The Node that references this Op</param>
1466 [DebuggerNonUserCode]
1467 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
1469 /// <summary>
1470 /// Visitor pattern method for visitors with a return value
1471 /// </summary>
1472 /// <param name="v">The visitor</param>
1473 /// <param name="n">The node in question</param>
1474 /// <returns>An instance of TResultType</returns>
1475 [DebuggerNonUserCode]
1476 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
1477 #endregion
1480 /// <summary>
1481 /// Extracts the ref from an entity instance
1482 /// </summary>
1483 internal sealed class GetEntityRefOp : ScalarOp
1485 #region constructors
1486 internal GetEntityRefOp(TypeUsage type) : base(OpType.GetEntityRef, type) { }
1487 private GetEntityRefOp() : base(OpType.GetEntityRef) { }
1488 #endregion
1490 #region public methods
1491 /// <summary>
1492 /// Pattern for transformation rules
1493 /// </summary>
1494 internal static readonly GetEntityRefOp Pattern = new GetEntityRefOp();
1496 /// <summary>
1497 /// 1 child - entity instance
1498 /// </summary>
1499 internal override int Arity { get { return 1; } }
1501 /// <summary>
1502 /// Visitor pattern method
1503 /// </summary>
1504 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
1505 /// <param name="n">The Node that references this Op</param>
1506 [DebuggerNonUserCode]
1507 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
1509 /// <summary>
1510 /// Visitor pattern method for visitors with a return value
1511 /// </summary>
1512 /// <param name="v">The visitor</param>
1513 /// <param name="n">The node in question</param>
1514 /// <returns>An instance of TResultType</returns>
1515 [DebuggerNonUserCode]
1516 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
1517 #endregion
1520 /// <summary>
1521 /// Gets the target entity pointed at by a reference
1522 /// </summary>
1523 internal sealed class DerefOp : ScalarOp
1525 #region constructors
1526 internal DerefOp(TypeUsage type) : base(OpType.Deref, type) { }
1527 private DerefOp() : base(OpType.Deref) { }
1528 #endregion
1530 #region public methods
1531 /// <summary>
1532 /// Pattern for transformation rules
1533 /// </summary>
1534 internal static readonly DerefOp Pattern = new DerefOp();
1536 /// <summary>
1537 /// 1 child - entity instance
1538 /// </summary>
1539 internal override int Arity { get { return 1; } }
1541 /// <summary>
1542 /// Visitor pattern method
1543 /// </summary>
1544 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
1545 /// <param name="n">The Node that references this Op</param>
1546 [DebuggerNonUserCode]
1547 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
1549 /// <summary>
1550 /// Visitor pattern method for visitors with a return value
1551 /// </summary>
1552 /// <param name="v">The visitor</param>
1553 /// <param name="n">The node in question</param>
1554 /// <returns>An instance of TResultType</returns>
1555 [DebuggerNonUserCode]
1556 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
1557 #endregion
1560 /// <summary>
1561 /// Navigate a relationship, and get the reference(s) of the target end
1562 /// </summary>
1563 internal sealed class NavigateOp : ScalarOp
1565 #region private state
1566 private readonly RelProperty m_property;
1567 #endregion
1569 #region constructors
1570 internal NavigateOp(TypeUsage type, RelProperty relProperty)
1571 : base(OpType.Navigate, type)
1573 m_property = relProperty;
1575 private NavigateOp() : base(OpType.Navigate) { }
1576 #endregion
1578 #region public methods
1579 /// <summary>
1580 /// Pattern for transformation rules
1581 /// </summary>
1582 internal static readonly NavigateOp Pattern = new NavigateOp();
1584 /// <summary>
1585 /// 1 child - entity instance
1586 /// </summary>
1587 internal override int Arity { get { return 1; } }
1589 /// <summary>
1590 /// The rel property that describes this nvaigation
1591 /// </summary>
1592 internal RelProperty RelProperty { get { return m_property; } }
1594 /// <summary>
1595 /// The relationship we're traversing
1596 /// </summary>
1597 internal RelationshipType Relationship { get { return m_property.Relationship; } }
1598 /// <summary>
1599 /// The starting point of the traversal
1600 /// </summary>
1601 internal RelationshipEndMember FromEnd { get { return m_property.FromEnd; } }
1602 /// <summary>
1603 /// The end-point of the traversal
1604 /// </summary>
1605 internal RelationshipEndMember ToEnd { get { return m_property.ToEnd; } }
1607 /// <summary>
1608 /// Visitor pattern method
1609 /// </summary>
1610 /// <param name="v">The BasicOpVisitor that is visiting this Op</param>
1611 /// <param name="n">The Node that references this Op</param>
1612 [DebuggerNonUserCode]
1613 internal override void Accept(BasicOpVisitor v, Node n) { v.Visit(this, n); }
1615 /// <summary>
1616 /// Visitor pattern method for visitors with a return value
1617 /// </summary>
1618 /// <param name="v">The visitor</param>
1619 /// <param name="n">The node in question</param>
1620 /// <returns>An instance of TResultType</returns>
1621 [DebuggerNonUserCode]
1622 internal override TResultType Accept<TResultType>(BasicOpVisitorOfT<TResultType> v, Node n) { return v.Visit(this, n); }
1623 #endregion