Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / System.Data.SqlXml / System / Xml / Xsl / QIL / QilExpression.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="QilExpression.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 // <owner current="true" primary="true">Microsoft</owner>
6 //------------------------------------------------------------------------------
7
8 using System.Collections.Generic;
9 using System.Xml.Xsl.Runtime;
10
11 namespace System.Xml.Xsl.Qil {
12
13     /// <summary>
14     /// The CQR implementation of QilExpression.
15     /// </summary>
16     /// <remarks>
17     ///    <p>QilExpression is the XML Query Intermediate Language invented by Michael Brundage and Chris Suver.
18     ///    QilExpression is an intermediate representation (IR) for all XML query and view languages.  QilExpression is
19     ///    designed for optimization, composition with virtual XML views, translation into other forms,
20     ///    and direct execution.  See also <a href="http://dynamo/qil/qil.xml">the QIL specification</a>.</p>
21     /// </remarks>
22     internal class QilExpression : QilNode {
23         private QilFactory  factory;
24         private QilNode     isDebug;
25         private QilNode     defWSet;
26         private QilNode     wsRules;
27         private QilNode     gloVars;
28         private QilNode     gloParams;
29         private QilNode     earlBnd;
30         private QilNode     funList;
31         private QilNode     rootNod;
32
33
34         //-----------------------------------------------
35         // Constructors
36         //-----------------------------------------------
37
38         /// <summary>
39         /// Construct QIL from a rooted graph of QilNodes with a new factory.
40         /// </summary>
41         public QilExpression(QilNodeType nodeType, QilNode root) : this(nodeType, root, new QilFactory()) {
42         }
43
44         /// <summary>
45         /// Construct QIL from a rooted graph of QilNodes with a specific factory.
46         /// </summary>
47         public QilExpression(QilNodeType nodeType, QilNode root, QilFactory factory) : base(nodeType) {
48             this.factory = factory;
49             this.isDebug = factory.False();
50
51             XmlWriterSettings settings = new XmlWriterSettings();
52             settings.ConformanceLevel = ConformanceLevel.Auto;
53             this.defWSet = factory.LiteralObject(settings);
54
55             this.wsRules = factory.LiteralObject(new List<WhitespaceRule>());
56             this.gloVars = factory.GlobalVariableList();
57             this.gloParams = factory.GlobalParameterList();
58             this.earlBnd = factory.LiteralObject(new List<EarlyBoundInfo>());
59             this.funList = factory.FunctionList();
60             this.rootNod = root;
61         }
62
63
64         //-----------------------------------------------
65         // IList<QilNode> methods -- override
66         //-----------------------------------------------
67
68         public override int Count {
69             get { return 8; }
70         }
71
72         public override QilNode this[int index] {
73             get {
74                 switch (index) {
75                     case 0: return this.isDebug;
76                     case 1: return this.defWSet;
77                     case 2: return this.wsRules;
78                     case 3: return this.gloParams;
79                     case 4: return this.gloVars;
80                     case 5: return this.earlBnd;
81                     case 6: return this.funList;
82                     case 7: return this.rootNod;
83                     default: throw new IndexOutOfRangeException();
84                 }
85             }
86             set {
87                 switch (index) {
88                     case 0: this.isDebug = value; break;
89                     case 1: this.defWSet = value; break;
90                     case 2: this.wsRules = value; break;
91                     case 3: this.gloParams = value; break;
92                     case 4: this.gloVars = value; break;
93                     case 5: this.earlBnd = value; break;
94                     case 6: this.funList = value; break;
95                     case 7: this.rootNod = value; break;
96                     default: throw new IndexOutOfRangeException();
97                 }
98             }
99         }
100
101
102         //-----------------------------------------------
103         // QilExpression methods
104         //-----------------------------------------------
105
106         /// <summary>
107         /// QilFactory to be used in constructing nodes in this graph.
108         /// </summary>
109         public QilFactory Factory {
110             get { return this.factory; }
111             set { this.factory = value; }
112         }
113
114         /// <summary>
115         /// True if this expression contains debugging information.
116         /// </summary>
117         public bool IsDebug {
118             get { return this.isDebug.NodeType == QilNodeType.True; }
119             set { this.isDebug = value ? this.factory.True() : this.factory.False(); }
120         }
121
122         /// <summary>
123         /// Default serialization options that will be used if the user does not supply a writer at execution time.
124         /// </summary>
125         public XmlWriterSettings DefaultWriterSettings {
126             get { return (XmlWriterSettings) ((QilLiteral) this.defWSet).Value; }
127             set {
128                 value.ReadOnly = true;
129                 ((QilLiteral) this.defWSet).Value = value;
130             }
131         }
132
133         /// <summary>
134         /// Xslt whitespace strip/preserve rules.
135         /// </summary>
136         public IList<WhitespaceRule> WhitespaceRules {
137             get { return (IList<WhitespaceRule>) ((QilLiteral) this.wsRules).Value; }
138             set { ((QilLiteral) this.wsRules).Value = value; }
139         }
140
141         /// <summary>
142         /// External parameters.
143         /// </summary>
144         public QilList GlobalParameterList {
145             get { return (QilList) this.gloParams; }
146             set { this.gloParams = value; }
147         }
148
149         /// <summary>
150         /// Global variables.
151         /// </summary>
152         public QilList GlobalVariableList {
153             get { return (QilList) this.gloVars; }
154             set { this.gloVars = value; }
155         }
156
157         /// <summary>
158         /// Early bound function objects.
159         /// </summary>
160         public IList<EarlyBoundInfo> EarlyBoundTypes {
161             get { return (IList<EarlyBoundInfo>) ((QilLiteral) this.earlBnd).Value; }
162             set { ((QilLiteral) this.earlBnd).Value = value; }
163         }
164
165         /// <summary>
166         /// Function definitions.
167         /// </summary>
168         public QilList FunctionList {
169             get { return (QilList) this.funList; }
170             set { this.funList = value; }
171         }
172
173         /// <summary>
174         /// The root node of the QilExpression graph
175         /// </summary>
176         public QilNode Root {
177             get { return this.rootNod; }
178             set { this.rootNod = value; }
179         }
180     }
181 }