1 //------------------------------------------------------------------------------
2 // <copyright file="QilExpression.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 // <owner current="true" primary="true">Microsoft</owner>
6 //------------------------------------------------------------------------------
8 using System.Collections.Generic;
9 using System.Xml.Xsl.Runtime;
11 namespace System.Xml.Xsl.Qil {
14 /// The CQR implementation of QilExpression.
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>
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;
34 //-----------------------------------------------
36 //-----------------------------------------------
39 /// Construct QIL from a rooted graph of QilNodes with a new factory.
41 public QilExpression(QilNodeType nodeType, QilNode root) : this(nodeType, root, new QilFactory()) {
45 /// Construct QIL from a rooted graph of QilNodes with a specific factory.
47 public QilExpression(QilNodeType nodeType, QilNode root, QilFactory factory) : base(nodeType) {
48 this.factory = factory;
49 this.isDebug = factory.False();
51 XmlWriterSettings settings = new XmlWriterSettings();
52 settings.ConformanceLevel = ConformanceLevel.Auto;
53 this.defWSet = factory.LiteralObject(settings);
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();
64 //-----------------------------------------------
65 // IList<QilNode> methods -- override
66 //-----------------------------------------------
68 public override int Count {
72 public override QilNode this[int 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();
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();
102 //-----------------------------------------------
103 // QilExpression methods
104 //-----------------------------------------------
107 /// QilFactory to be used in constructing nodes in this graph.
109 public QilFactory Factory {
110 get { return this.factory; }
111 set { this.factory = value; }
115 /// True if this expression contains debugging information.
117 public bool IsDebug {
118 get { return this.isDebug.NodeType == QilNodeType.True; }
119 set { this.isDebug = value ? this.factory.True() : this.factory.False(); }
123 /// Default serialization options that will be used if the user does not supply a writer at execution time.
125 public XmlWriterSettings DefaultWriterSettings {
126 get { return (XmlWriterSettings) ((QilLiteral) this.defWSet).Value; }
128 value.ReadOnly = true;
129 ((QilLiteral) this.defWSet).Value = value;
134 /// Xslt whitespace strip/preserve rules.
136 public IList<WhitespaceRule> WhitespaceRules {
137 get { return (IList<WhitespaceRule>) ((QilLiteral) this.wsRules).Value; }
138 set { ((QilLiteral) this.wsRules).Value = value; }
142 /// External parameters.
144 public QilList GlobalParameterList {
145 get { return (QilList) this.gloParams; }
146 set { this.gloParams = value; }
150 /// Global variables.
152 public QilList GlobalVariableList {
153 get { return (QilList) this.gloVars; }
154 set { this.gloVars = value; }
158 /// Early bound function objects.
160 public IList<EarlyBoundInfo> EarlyBoundTypes {
161 get { return (IList<EarlyBoundInfo>) ((QilLiteral) this.earlBnd).Value; }
162 set { ((QilLiteral) this.earlBnd).Value = value; }
166 /// Function definitions.
168 public QilList FunctionList {
169 get { return (QilList) this.funList; }
170 set { this.funList = value; }
174 /// The root node of the QilExpression graph
176 public QilNode Root {
177 get { return this.rootNod; }
178 set { this.rootNod = value; }