1 //------------------------------------------------------------------------------
2 // <copyright file="QilNode.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 // <owner current="true" primary="true">Microsoft</owner>
6 //------------------------------------------------------------------------------
8 using System
.Collections
;
9 using System
.Collections
.Generic
;
10 using System
.Diagnostics
;
11 using System
.Globalization
;
13 using System
.Xml
.Schema
;
16 namespace System
.Xml
.Xsl
.Qil
{
19 /// A node in the QIL tree.
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).
25 internal class QilNode
: IList
<QilNode
> {
26 protected QilNodeType nodeType
;
27 protected XmlQueryType xmlType
;
28 protected ISourceLineInfo sourceLine
;
29 protected object annotation
;
31 //-----------------------------------------------
33 //-----------------------------------------------
36 /// Construct a new node
38 public QilNode(QilNodeType nodeType
) {
39 this.nodeType
= nodeType
;
43 /// Construct a new node
45 public QilNode(QilNodeType nodeType
, XmlQueryType xmlType
) {
46 this.nodeType
= nodeType
;
47 this.xmlType
= xmlType
;
51 //-----------------------------------------------
53 //-----------------------------------------------
56 /// Access the QIL node type.
58 public QilNodeType NodeType
{
59 get { return this.nodeType; }
60 set { this.nodeType = value; }
64 /// Access the QIL type.
66 public virtual XmlQueryType XmlType
{
67 get { return this.xmlType; }
68 set { this.xmlType = value; }
72 /// Line info information for tools support.
74 public ISourceLineInfo SourceLine
{
75 get { return this.sourceLine; }
76 set { this.sourceLine = value; }
80 /// Access an annotation which may have been attached to this node.
82 public object Annotation
{
83 get { return this.annotation; }
84 set { this.annotation = value; }
88 /// Create a new deep copy of this node.
90 public virtual QilNode
DeepClone(QilFactory f
) {
91 return new QilCloneVisitor(f
).Clone(this);
95 /// Create a shallow copy of this node, copying all the fields.
97 public virtual QilNode
ShallowClone(QilFactory f
) {
98 QilNode n
= (QilNode
) MemberwiseClone();
104 //-----------------------------------------------
105 // IList<QilNode> methods -- override
106 //-----------------------------------------------
108 public virtual int Count
{
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
) {
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
--)
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
);
174 public virtual int IndexOf(QilNode node
) {
175 for (int i
= 0; i
< Count
; i
++)
176 if (node
.Equals(this[i
]))
183 //-----------------------------------------------
185 //-----------------------------------------------
187 #if QIL_TRACE_NODE_CREATION
189 private string nodeLoc
;
192 get { return nodeId; }
193 set { nodeId = value; }
196 public string NodeLocation
{
197 get { return nodeLoc; }
198 set { nodeLoc = value; }