The Labs \ Source Viewer \ SSCLI \ System.Xml.Xsl.IlGen \ XmlILAnnotation

  1. //------------------------------------------------------------------------------
  2. // <copyright file="XmlILAnnotation.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.Reflection;
  17. using System.Xml.Xsl.Qil;
  18. namespace System.Xml.Xsl.IlGen
  19. {
  20.    
  21.     /// <summary>
  22.     /// Several annotations are created and attached to Qil nodes during the optimization and code generation phase.
  23.     /// </summary>
  24.     internal class XmlILAnnotation : ListBase<object>
  25.     {
  26.         private object annPrev;
  27.         private MethodInfo funcMethod;
  28.         private int argPos;
  29.         private IteratorDescriptor iterInfo;
  30.         private XmlILConstructInfo constrInfo;
  31.         private OptimizerPatterns optPatt;
  32.        
  33.        
  34.         //-----------------------------------------------
  35.         // Constructor
  36.         //-----------------------------------------------
  37.        
  38.         /// <summary>
  39.         /// Create and initialize XmlILAnnotation for the specified node.
  40.         /// </summary>
  41.         public static XmlILAnnotation Write(QilNode nd)
  42.         {
  43.             XmlILAnnotation ann = nd.Annotation as XmlILAnnotation;
  44.            
  45.             if (ann == null) {
  46.                 ann = new XmlILAnnotation(nd.Annotation);
  47.                 nd.Annotation = ann;
  48.             }
  49.            
  50.             return ann;
  51.         }
  52.        
  53.         private XmlILAnnotation(object annPrev)
  54.         {
  55.             this.annPrev = annPrev;
  56.         }
  57.        
  58.        
  59.         //-----------------------------------------------
  60.         // Annotations
  61.         //-----------------------------------------------
  62.        
  63.         /// <summary>
  64.         /// User-defined functions and global variables and parameters are bound to Clr MethodInfo objects.
  65.         /// Attached to Function, global Let, and global Parameter nodes.
  66.         /// </summary>
  67.         public MethodInfo FunctionBinding {
  68.             get { return this.funcMethod; }
  69.             set { this.funcMethod = value; }
  70.         }
  71.        
  72.         /// <summary>
  73.         /// Function arguments are tracked by position.
  74.         /// Attached to function Parameter nodes.
  75.         /// </summary>
  76.         public int ArgumentPosition {
  77.             get { return this.argPos; }
  78.             set { this.argPos = value; }
  79.         }
  80.        
  81.         /// <summary>
  82.         /// The IteratorDescriptor that is derived for Qil For and Let nodes is cached so that it can be used when the
  83.         /// For/Let node is referenced.
  84.         /// Attached to For and Let nodes.
  85.         /// </summary>
  86.         public IteratorDescriptor CachedIteratorDescriptor {
  87.             get { return this.iterInfo; }
  88.             set { this.iterInfo = value; }
  89.         }
  90.        
  91.         /// <summary>
  92.         /// Contains information about how this expression will be constructed by ILGen.
  93.         /// Attached to any kind of Qil node.
  94.         /// </summary>
  95.         public XmlILConstructInfo ConstructInfo {
  96.             get { return this.constrInfo; }
  97.             set { this.constrInfo = value; }
  98.         }
  99.        
  100.         /// <summary>
  101.         /// Contains patterns that the subtree rooted at this node matches.
  102.         /// Attached to any kind of Qil node.
  103.         /// </summary>
  104.         public OptimizerPatterns Patterns {
  105.             get { return this.optPatt; }
  106.             set { this.optPatt = value; }
  107.         }
  108.        
  109.        
  110.         //-----------------------------------------------
  111.         // ListBase implementation
  112.         //-----------------------------------------------
  113.        
  114.         /// <summary>
  115.         /// Return the count of sub-annotations maintained by this annotation.
  116.         /// </summary>
  117.         public override int Count {
  118.             get { return (this.annPrev != null) ? 3 : 2; }
  119.         }
  120.        
  121.         /// <summary>
  122.         /// Return the annotation at the specified index.
  123.         /// </summary>
  124.         public override object this[int index]
  125.         {
  126.             get {
  127.                 if (this.annPrev != null) {
  128.                     if (index == 0)
  129.                         return this.annPrev;
  130.                    
  131.                     index--;
  132.                 }
  133.                
  134.                 switch (index) {
  135.                     case 0:
  136.                         return this.constrInfo;
  137.                     case 1:
  138.                         return this.optPatt;
  139.                 }
  140.                
  141.                 throw new IndexOutOfRangeException();
  142.             }
  143.             set {
  144.                 throw new NotSupportedException();
  145.             }
  146.         }
  147.     }
  148. }

Developer Fusion