Updates referencesource to .NET 4.7
[mono-project.git] / mcs / class / referencesource / System.Data.SqlXml / System / Xml / Xsl / QIL / QilNode.cs
blob6eefb53f22a1b810186d58575419d68e7b2f34a4
1 //------------------------------------------------------------------------------
2 // <copyright file="QilNode.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
4 // </copyright>
5 // <owner current="true" primary="true">Microsoft</owner>
6 //------------------------------------------------------------------------------
7 using System;
8 using System.Collections;
9 using System.Collections.Generic;
10 using System.Diagnostics;
11 using System.Globalization;
12 using System.Xml;
13 using System.Xml.Schema;
14 using System.Xml.Xsl;
16 namespace System.Xml.Xsl.Qil {
18 /// <summary>
19 /// A node in the QIL tree.
20 /// </summary>
21 /// <remarks>
22 /// Don't construct QIL nodes directly; instead, use the <see cref="QilFactory">QilFactory</see>.
23 /// This base internal class is not abstract and may be instantiated in some cases (for example, true/false boolean literals).
24 /// </remarks>
25 internal class QilNode : IList<QilNode> {
26 protected QilNodeType nodeType;
27 protected XmlQueryType xmlType;
28 protected ISourceLineInfo sourceLine;
29 protected object annotation;
31 //-----------------------------------------------
32 // Constructor
33 //-----------------------------------------------
35 /// <summary>
36 /// Construct a new node
37 /// </summary>
38 public QilNode(QilNodeType nodeType) {
39 this.nodeType = nodeType;
42 /// <summary>
43 /// Construct a new node
44 /// </summary>
45 public QilNode(QilNodeType nodeType, XmlQueryType xmlType) {
46 this.nodeType = nodeType;
47 this.xmlType = xmlType;
51 //-----------------------------------------------
52 // QilNode methods
53 //-----------------------------------------------
55 /// <summary>
56 /// Access the QIL node type.
57 /// </summary>
58 public QilNodeType NodeType {
59 get { return this.nodeType; }
60 set { this.nodeType = value; }
63 /// <summary>
64 /// Access the QIL type.
65 /// </summary>
66 public virtual XmlQueryType XmlType {
67 get { return this.xmlType; }
68 set { this.xmlType = value; }
71 /// <summary>
72 /// Line info information for tools support.
73 /// </summary>
74 public ISourceLineInfo SourceLine {
75 get { return this.sourceLine; }
76 set { this.sourceLine = value; }
79 /// <summary>
80 /// Access an annotation which may have been attached to this node.
81 /// </summary>
82 public object Annotation {
83 get { return this.annotation; }
84 set { this.annotation = value; }
87 /// <summary>
88 /// Create a new deep copy of this node.
89 /// </summary>
90 public virtual QilNode DeepClone(QilFactory f) {
91 return new QilCloneVisitor(f).Clone(this);
94 /// <summary>
95 /// Create a shallow copy of this node, copying all the fields.
96 /// </summary>
97 public virtual QilNode ShallowClone(QilFactory f) {
98 QilNode n = (QilNode) MemberwiseClone();
99 f.TraceNode(n);
100 return n;
104 //-----------------------------------------------
105 // IList<QilNode> methods -- override
106 //-----------------------------------------------
108 public virtual int Count {
109 get { return 0; }
112 public virtual QilNode this[int index] {
113 get { throw new IndexOutOfRangeException(); }
114 set { throw new IndexOutOfRangeException(); }
117 public virtual void Insert(int index, QilNode node) {
118 throw new NotSupportedException();
121 public virtual void RemoveAt(int index) {
122 throw new NotSupportedException();
126 //-----------------------------------------------
127 // IList<QilNode> methods -- no need to override
128 //-----------------------------------------------
130 public IEnumerator<QilNode> GetEnumerator() {
131 return new IListEnumerator<QilNode>(this);
134 IEnumerator IEnumerable.GetEnumerator() {
135 return new IListEnumerator<QilNode>(this);
138 public virtual bool IsReadOnly {
139 get { return false; }
142 public virtual void Add(QilNode node) {
143 Insert(Count, node);
146 public virtual void Add(IList<QilNode> list) {
147 for (int i = 0; i < list.Count; i++)
148 Insert(Count, list[i]);
151 public virtual void Clear() {
152 for (int index = Count - 1; index >= 0; index--)
153 RemoveAt(index);
156 public virtual bool Contains(QilNode node) {
157 return IndexOf(node) != -1;
160 public virtual void CopyTo(QilNode[] array, int index) {
161 for (int i = 0; i < Count; i++)
162 array[index + i] = this[i];
165 public virtual bool Remove(QilNode node) {
166 int index = IndexOf(node);
167 if (index >= 0) {
168 RemoveAt(index);
169 return true;
171 return false;
174 public virtual int IndexOf(QilNode node) {
175 for (int i = 0; i < Count; i++)
176 if (node.Equals(this[i]))
177 return i;
179 return -1;
183 //-----------------------------------------------
184 // Debug
185 //-----------------------------------------------
187 #if QIL_TRACE_NODE_CREATION
188 private int nodeId;
189 private string nodeLoc;
191 public int NodeId {
192 get { return nodeId; }
193 set { nodeId = value; }
196 public string NodeLocation {
197 get { return nodeLoc; }
198 set { nodeLoc = value; }
200 #endif