1 //------------------------------------------------------------------------------
2 // <copyright file="XmlILAnnotation.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 // <owner current="true" primary="true">[....]</owner>
6 //------------------------------------------------------------------------------
8 using System.Reflection;
9 using System.Xml.Xsl.Qil;
11 namespace System.Xml.Xsl.IlGen {
14 /// Several annotations are created and attached to Qil nodes during the optimization and code generation phase.
16 internal class XmlILAnnotation : ListBase<object> {
17 private object annPrev;
18 private MethodInfo funcMethod;
20 private IteratorDescriptor iterInfo;
21 private XmlILConstructInfo constrInfo;
22 private OptimizerPatterns optPatt;
25 //-----------------------------------------------
27 //-----------------------------------------------
30 /// Create and initialize XmlILAnnotation for the specified node.
32 public static XmlILAnnotation Write(QilNode nd) {
33 XmlILAnnotation ann = nd.Annotation as XmlILAnnotation;
36 ann = new XmlILAnnotation(nd.Annotation);
43 private XmlILAnnotation(object annPrev) {
44 this.annPrev = annPrev;
48 //-----------------------------------------------
50 //-----------------------------------------------
53 /// User-defined functions and global variables and parameters are bound to Clr MethodInfo objects.
54 /// Attached to Function, global Let, and global Parameter nodes.
56 public MethodInfo FunctionBinding {
57 get { return this.funcMethod; }
58 set { this.funcMethod = value; }
62 /// Function arguments are tracked by position.
63 /// Attached to function Parameter nodes.
65 public int ArgumentPosition {
66 get { return this.argPos; }
67 set { this.argPos = value; }
71 /// The IteratorDescriptor that is derived for Qil For and Let nodes is cached so that it can be used when the
72 /// For/Let node is referenced.
73 /// Attached to For and Let nodes.
75 public IteratorDescriptor CachedIteratorDescriptor {
76 get { return this.iterInfo; }
77 set { this.iterInfo = value; }
81 /// Contains information about how this expression will be constructed by ILGen.
82 /// Attached to any kind of Qil node.
84 public XmlILConstructInfo ConstructInfo {
85 get { return this.constrInfo; }
86 set { this.constrInfo = value; }
90 /// Contains patterns that the subtree rooted at this node matches.
91 /// Attached to any kind of Qil node.
93 public OptimizerPatterns Patterns {
94 get { return this.optPatt; }
95 set { this.optPatt = value; }
99 //-----------------------------------------------
100 // ListBase implementation
101 //-----------------------------------------------
104 /// Return the count of sub-annotations maintained by this annotation.
106 public override int Count {
107 get { return (this.annPrev != null) ? 3 : 2; }
111 /// Return the annotation at the specified index.
113 public override object this[int index] {
115 if (this.annPrev != null) {
123 case 0: return this.constrInfo;
124 case 1: return this.optPatt;
127 throw new IndexOutOfRangeException();
130 throw new NotSupportedException();