Update Reference Sources to .NET Framework 4.6.1
[mono.git] / mcs / class / referencesource / System.Data.SqlXml / System / Xml / Xsl / IlGen / XmlILAnnotation.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="XmlILAnnotation.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 // <owner current="true" primary="true">[....]</owner>
6 //------------------------------------------------------------------------------
7 using System;
8 using System.Reflection;
9 using System.Xml.Xsl.Qil;
10
11 namespace System.Xml.Xsl.IlGen {
12
13     /// <summary>
14     /// Several annotations are created and attached to Qil nodes during the optimization and code generation phase.
15     /// </summary>
16     internal class XmlILAnnotation : ListBase<object> {
17         private object annPrev;
18         private MethodInfo funcMethod;
19         private int argPos;
20         private IteratorDescriptor iterInfo;
21         private XmlILConstructInfo constrInfo;
22         private OptimizerPatterns optPatt;
23
24
25         //-----------------------------------------------
26         // Constructor
27         //-----------------------------------------------
28
29         /// <summary>
30         /// Create and initialize XmlILAnnotation for the specified node.
31         /// </summary>
32         public static XmlILAnnotation Write(QilNode nd) {
33             XmlILAnnotation ann = nd.Annotation as XmlILAnnotation;
34
35             if (ann == null) {
36                 ann = new XmlILAnnotation(nd.Annotation);
37                 nd.Annotation = ann;
38             }
39
40             return ann;
41         }
42
43         private XmlILAnnotation(object annPrev) {
44             this.annPrev = annPrev;
45         }
46
47
48         //-----------------------------------------------
49         // Annotations
50         //-----------------------------------------------
51
52         /// <summary>
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.
55         /// </summary>
56         public MethodInfo FunctionBinding {
57             get { return this.funcMethod; }
58             set { this.funcMethod = value; }
59         }
60
61         /// <summary>
62         /// Function arguments are tracked by position.
63         /// Attached to function Parameter nodes.
64         /// </summary>
65         public int ArgumentPosition {
66             get { return this.argPos; }
67             set { this.argPos = value; }
68         }
69
70         /// <summary>
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.
74         /// </summary>
75         public IteratorDescriptor CachedIteratorDescriptor {
76             get { return this.iterInfo; }
77             set { this.iterInfo = value; }
78         }
79
80         /// <summary>
81         /// Contains information about how this expression will be constructed by ILGen.
82         /// Attached to any kind of Qil node.
83         /// </summary>
84         public XmlILConstructInfo ConstructInfo {
85             get { return this.constrInfo; }
86             set { this.constrInfo = value; }
87         }
88
89         /// <summary>
90         /// Contains patterns that the subtree rooted at this node matches.
91         /// Attached to any kind of Qil node.
92         /// </summary>
93         public OptimizerPatterns Patterns {
94             get { return this.optPatt; }
95             set { this.optPatt = value; }
96         }
97
98
99         //-----------------------------------------------
100         // ListBase implementation
101         //-----------------------------------------------
102
103         /// <summary>
104         /// Return the count of sub-annotations maintained by this annotation.
105         /// </summary>
106         public override int Count {
107             get { return (this.annPrev != null) ? 3 : 2; }
108         }
109
110         /// <summary>
111         /// Return the annotation at the specified index.
112         /// </summary>
113         public override object this[int index] {
114             get {
115                 if (this.annPrev != null) {
116                     if (index == 0)
117                         return this.annPrev;
118
119                     index--;
120                 }
121
122                 switch (index) {
123                     case 0: return this.constrInfo;
124                     case 1: return this.optPatt;
125                 }
126
127                 throw new IndexOutOfRangeException();
128             }
129             set {
130                 throw new NotSupportedException();
131             }
132         }
133     }
134 }