The Labs \ Source Viewer \ SSCLI \ System.Xml.Xsl.Qil \ QilFunction

  1. //------------------------------------------------------------------------------
  2. // <copyright file="QilFunction.cs" company="Microsoft">
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. // </copyright>
  14. //------------------------------------------------------------------------------
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Diagnostics;
  18. namespace System.Xml.Xsl.Qil
  19. {
  20.    
  21.     /// <summary>
  22.     /// An anonymous QilExpression function node.
  23.     /// </summary>
  24.     /// <remarks>
  25.     /// <para>Function is a block, so it may introduce assignments (scoped to the function body).
  26.     /// Additionally, it has an argument list, which will be assigned values
  27.     /// when the function is invoked.</para>
  28.     /// <para>The XmlType property defines the expected return type of this function.
  29.     /// Normally, this should be the same as its definition's types, so setting the function
  30.     /// definition changes the function's types. In some rare cases, a compiler may wish to
  31.     /// override the types after setting the function's definition (for example, an XQuery
  32.     /// might define a function's return type to be wider than its definition would imply.)</para>
  33.     /// </remarks>
  34.     internal class QilFunction : QilReference
  35.     {
  36.         private QilNode arguments, definition, sideEffects;
  37.        
  38.         //-----------------------------------------------
  39.         // Constructor
  40.         //-----------------------------------------------
  41.        
  42.         /// <summary>
  43.         /// Construct a node
  44.         /// </summary>
  45.         public QilFunction(QilNodeType nodeType, QilNode arguments, QilNode definition, QilNode sideEffects, XmlQueryType resultType) : base(nodeType)
  46.         {
  47.             this.arguments = arguments;
  48.             this.definition = definition;
  49.             this.sideEffects = sideEffects;
  50.             this.xmlType = resultType;
  51.         }
  52.        
  53.        
  54.         //-----------------------------------------------
  55.         // IList<QilNode> methods -- override
  56.         //-----------------------------------------------
  57.        
  58.         public override int Count {
  59.             get { return 3; }
  60.         }
  61.        
  62.         public override QilNode this[int index]
  63.         {
  64.             get {
  65.                 switch (index) {
  66.                     case 0:
  67.                         return this.arguments;
  68.                     case 1:
  69.                         return this.definition;
  70.                     case 2:
  71.                         return this.sideEffects;
  72.                     default:
  73.                         throw new IndexOutOfRangeException();
  74.                         break;
  75.                 }
  76.             }
  77.             set {
  78.                 switch (index) {
  79.                     case 0:
  80.                         this.arguments = value;
  81.                         break;
  82.                     case 1:
  83.                         this.definition = value;
  84.                         break;
  85.                     case 2:
  86.                         this.sideEffects = value;
  87.                         break;
  88.                     default:
  89.                         throw new IndexOutOfRangeException();
  90.                         break;
  91.                 }
  92.             }
  93.         }
  94.        
  95.        
  96.         //-----------------------------------------------
  97.         // QilFunction methods
  98.         //-----------------------------------------------
  99.        
  100.         /// <summary>
  101.         /// Formal arguments of this function.
  102.         /// </summary>
  103.         public QilList Arguments {
  104.             get { return (QilList)this.arguments; }
  105.             set { this.arguments = value; }
  106.         }
  107.        
  108.         /// <summary>
  109.         /// Body of this function.
  110.         /// </summary>
  111.         public QilNode Definition {
  112.             get { return this.definition; }
  113.             set { this.definition = value; }
  114.         }
  115.        
  116.         /// <summary>
  117.         /// QilNodeType.True if this function might have side-effects.
  118.         /// </summary>
  119.         public bool MaybeSideEffects {
  120.             get { return this.sideEffects.NodeType == QilNodeType.True; }
  121.             set { this.sideEffects.NodeType = value ? QilNodeType.True : QilNodeType.False; }
  122.         }
  123.     }
  124. }

Developer Fusion