XPath2Expression.cs 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242
  1. //
  2. // XPath2Expression.cs - abstract syntax tree for XPath 2.0
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. //
  8. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. #if NET_2_0
  30. using System;
  31. using System.Collections;
  32. using System.Globalization;
  33. using System.Xml;
  34. using System.Xml.Query;
  35. using System.Xml.Schema;
  36. using System.Xml.XPath;
  37. using Mono.Xml.XQuery;
  38. namespace Mono.Xml.XPath2
  39. {
  40. public class ExprSequence : CollectionBase
  41. {
  42. public ExprSequence ()
  43. {
  44. }
  45. public void Add (ExprSingle expr)
  46. {
  47. List.Add (expr);
  48. }
  49. public void AddRange (ICollection items)
  50. {
  51. if (items != null)
  52. foreach (ExprSingle e in items)
  53. List.Add (e);
  54. }
  55. public void Insert (int pos, ExprSingle expr)
  56. {
  57. List.Insert (pos, expr);
  58. }
  59. public ExprSingle this [int i] {
  60. get { return List [i] as ExprSingle; }
  61. set { List [i] = value; }
  62. }
  63. internal void CheckReference (XQueryASTCompiler compiler)
  64. {
  65. foreach (ExprSingle expr in List)
  66. expr.CheckReference (compiler);
  67. }
  68. }
  69. public abstract class ExprSingle
  70. {
  71. internal abstract void CheckReference (XQueryASTCompiler compiler);
  72. #region CompileAndEvaluate
  73. internal static readonly XPathAtomicValue AtomicTrue = new XPathAtomicValue (true, XmlSchemaSimpleType.XsBoolean);
  74. internal static readonly XPathAtomicValue AtomicFalse = new XPathAtomicValue (false, XmlSchemaSimpleType.XsBoolean);
  75. XQueryStaticContext ctx;
  76. internal ExprSingle Compile (XQueryASTCompiler compiler)
  77. {
  78. this.ctx = ctx;
  79. return CompileCore (compiler);
  80. }
  81. // If internal&&protected is available in C#, it is the best signature.
  82. internal abstract ExprSingle CompileCore (XQueryASTCompiler compiler);
  83. internal XQueryStaticContext Context {
  84. get { return ctx; }
  85. }
  86. public abstract SequenceType StaticType { get; }
  87. /** <summary>
  88. This is the core part of ExprSingle. It is
  89. generally used to evaluate expression and returns
  90. XPathItem sequence (iterator). The result is unordered
  91. */
  92. public abstract XPathSequence Evaluate (XPathSequence iter);
  93. public virtual XPathSequence EvaluateOrdered (XPathSequence iter)
  94. {
  95. if (RequireSorting) {
  96. ArrayList al = new ArrayList ();
  97. foreach (XPathItem item in Evaluate (iter))
  98. al.Add (item);
  99. return new ListIterator (iter, al);
  100. }
  101. else
  102. return Evaluate (iter);
  103. }
  104. public virtual void Serialize (XPathSequence iter)
  105. {
  106. XmlWriter w = iter.Context.Writer;
  107. XPathSequence result = Evaluate (iter);
  108. bool initial = true;
  109. foreach (XPathItem item in result) {
  110. if (initial)
  111. initial = false;
  112. else
  113. w.WriteWhitespace (" ");
  114. WriteXPathItem (item, w);
  115. }
  116. }
  117. private void WriteXPathItem (XPathItem item, XmlWriter w)
  118. {
  119. if (item.IsNode) {
  120. XPathNavigator nav = item as XPathNavigator;
  121. if (w.WriteState != WriteState.Start && nav.NodeType == XPathNodeType.Root)
  122. throw new XmlQueryException ("Current output can not accept root node.");
  123. nav.WriteSubtree (w);
  124. } else
  125. w.WriteValue (item.Value);
  126. }
  127. // get EBV (fn:boolean())
  128. public virtual bool EvaluateAsBoolean (XPathSequence iter)
  129. {
  130. XPathSequence result = Evaluate (iter);
  131. if (!result.MoveNext ())
  132. return false;
  133. XPathItem v = result.Current;
  134. if (v is XPathNavigator)
  135. return true;
  136. if (result.MoveNext ())
  137. return true;
  138. switch (v.XmlType.TypeCode) {
  139. case XmlTypeCode.Boolean:
  140. return v.ValueAsBoolean;
  141. case XmlTypeCode.String:
  142. case XmlTypeCode.UntypedAtomic:
  143. return v.Value != String.Empty;
  144. case XmlTypeCode.Float:
  145. return v.ValueAsSingle != Single.NaN && v.ValueAsSingle != 0.0;
  146. case XmlTypeCode.Double:
  147. return v.ValueAsDouble != Double.NaN && v.ValueAsSingle != 0.0;
  148. case XmlTypeCode.Integer:
  149. case XmlTypeCode.NonPositiveInteger:
  150. case XmlTypeCode.NegativeInteger:
  151. case XmlTypeCode.Long:
  152. case XmlTypeCode.Int:
  153. case XmlTypeCode.Short:
  154. case XmlTypeCode.Byte:
  155. case XmlTypeCode.UnsignedInt:
  156. case XmlTypeCode.UnsignedShort:
  157. case XmlTypeCode.UnsignedByte:
  158. return v.ValueAsInt64 != 0;
  159. case XmlTypeCode.NonNegativeInteger:
  160. case XmlTypeCode.UnsignedLong:
  161. case XmlTypeCode.PositiveInteger:
  162. return (ulong) (v.ValueAs (typeof (ulong))) != 0;
  163. }
  164. // otherwise, return true
  165. return true;
  166. }
  167. public virtual int EvaluateAsInt (XPathSequence iter)
  168. {
  169. XPathAtomicValue v = Atomize (Evaluate (iter));
  170. return v != null ? v.ValueAsInt32 : 0;
  171. }
  172. public virtual string EvaluateAsString (XPathSequence iter)
  173. {
  174. XPathAtomicValue v = Atomize (Evaluate (iter));
  175. return v != null ? v.Value : String.Empty;
  176. }
  177. public static XPathAtomicValue Atomize (XPathItem item)
  178. {
  179. XPathNavigator nav = item as XPathNavigator;
  180. if (nav != null) {
  181. if (nav.SchemaInfo != null)
  182. return new XPathAtomicValue (nav.TypedValue, nav.SchemaInfo.SchemaType);
  183. else
  184. return new XPathAtomicValue (nav.Value, XmlSchemaSimpleType.XsString);
  185. }
  186. else
  187. return (XPathAtomicValue) item;
  188. }
  189. // FIXME: What if iter contains list value?
  190. public static XPathAtomicValue Atomize (XPathSequence iter)
  191. {
  192. if (!iter.MoveNext ())
  193. return null;
  194. XPathNavigator nav = iter.Current as XPathNavigator;
  195. if (nav != null)
  196. return new XPathAtomicValue (nav.TypedValue, nav.SchemaInfo.SchemaType);
  197. else
  198. return (XPathAtomicValue) iter.Current;
  199. }
  200. public virtual XPathAtomicValue EvaluateAsAtomic (XPathSequence iter)
  201. {
  202. return Atomize (Evaluate (iter));
  203. }
  204. public virtual bool RequireSorting {
  205. get { return false; }
  206. }
  207. #endregion
  208. }
  209. // FLWORExpr
  210. internal class FLWORExpr : ExprSingle
  211. {
  212. public FLWORExpr (ForLetClauseCollection forlet, ExprSequence whereClause, OrderSpecList orderBy, ExprSingle ret)
  213. {
  214. this.fl = forlet;
  215. this.whereClause = new ParenthesizedExpr (whereClause);
  216. this.orderBy = orderBy;
  217. this.ret = ret;
  218. }
  219. ForLetClauseCollection fl;
  220. ExprSingle whereClause;
  221. OrderSpecList orderBy;
  222. ExprSingle ret;
  223. public ForLetClauseCollection ForLetClauses {
  224. get { return fl; }
  225. }
  226. public ExprSingle WhereClause {
  227. get { return whereClause; }
  228. }
  229. public OrderSpecList OrderBy {
  230. get { return orderBy; }
  231. }
  232. public ExprSingle ReturnExpr {
  233. get { return ret; }
  234. set { ret = value; }
  235. }
  236. // ExprSingle Overrides
  237. internal override void CheckReference (XQueryASTCompiler compiler)
  238. {
  239. foreach (ForLetClause flc in fl)
  240. foreach (ForLetSingleBody single in flc)
  241. single.CheckReference (compiler);
  242. if (whereClause != null)
  243. whereClause.CheckReference (compiler);
  244. if (orderBy != null)
  245. foreach (OrderSpec os in orderBy)
  246. os.Expression.CheckReference (compiler);
  247. ret.CheckReference (compiler);
  248. }
  249. #region CompileAndEvaluate
  250. internal override ExprSingle CompileCore (XQueryASTCompiler compiler)
  251. {
  252. foreach (ForLetClause flc in ForLetClauses) {
  253. foreach (ForLetSingleBody flsb in flc) {
  254. flsb.Expression = flsb.Expression.Compile (compiler);
  255. if (flsb.ReturnType != null)
  256. compiler.CheckType (flsb.Expression, flsb.ReturnType);
  257. }
  258. }
  259. if (WhereClause != null)
  260. // for (int i = 0; i < WhereClause.Count; i++)
  261. // WhereClause [i] = WhereClause [i].Compile (compiler);
  262. whereClause = whereClause.Compile (compiler);
  263. if (OrderBy != null)
  264. foreach (OrderSpec os in OrderBy)
  265. os.Expression = os.Expression.Compile (compiler);
  266. ReturnExpr = ReturnExpr.Compile (compiler);
  267. return this;
  268. }
  269. public override SequenceType StaticType {
  270. get { return ReturnExpr.StaticType; }
  271. }
  272. public override XPathSequence Evaluate (XPathSequence iter)
  273. {
  274. return new FLWORIterator (iter, this);
  275. }
  276. #endregion
  277. }
  278. internal class ForLetClauseCollection : CollectionBase
  279. {
  280. public void Add (ForLetClause clause)
  281. {
  282. List.Add (clause);
  283. }
  284. public void Insert (int pos, ForLetClause clause)
  285. {
  286. List.Insert (pos, clause);
  287. }
  288. public ForLetClause this [int i] {
  289. get { return (ForLetClause) List [i]; }
  290. }
  291. }
  292. internal class OrderSpecList : CollectionBase
  293. {
  294. bool isStable;
  295. public OrderSpecList ()
  296. {
  297. }
  298. public bool IsStable {
  299. get { return isStable; }
  300. set { isStable = value; }
  301. }
  302. public void Insert (int pos, OrderSpec os)
  303. {
  304. List.Insert (pos, os);
  305. }
  306. public void Add (OrderSpec spec)
  307. {
  308. List.Add (spec);
  309. }
  310. public OrderSpec this [int i] {
  311. get { return (OrderSpec) List [i]; }
  312. }
  313. }
  314. internal class OrderSpec
  315. {
  316. public OrderSpec (ExprSingle expr, OrderModifier modifier)
  317. {
  318. this.expr = expr;
  319. this.mod = modifier;
  320. }
  321. ExprSingle expr;
  322. OrderModifier mod;
  323. public ExprSingle Expression {
  324. get {return expr; }
  325. set { expr = value; }
  326. }
  327. public OrderModifier Modifier {
  328. get { return mod; }
  329. set { mod = value; }
  330. }
  331. }
  332. internal class OrderModifier
  333. {
  334. public OrderModifier (XmlSortOrder order, XmlSortOrder emptyOrder, string collation)
  335. {
  336. this.sortOrder = sortOrder;
  337. this.emptyOrder = emptyOrder;
  338. if (collation != null)
  339. this.coll = new CultureInfo (collation);
  340. }
  341. XmlSortOrder sortOrder;
  342. XmlSortOrder emptyOrder;
  343. CultureInfo coll;
  344. public XmlSortOrder SortOrder {
  345. get { return sortOrder; }
  346. }
  347. public XmlSortOrder EmptyOrder {
  348. get { return emptyOrder; }
  349. }
  350. public CultureInfo Collation {
  351. get { return coll; }
  352. }
  353. }
  354. internal class ForLetClause : CollectionBase
  355. {
  356. public ForLetSingleBody this [int i] {
  357. get { return (ForLetSingleBody) List [i]; }
  358. }
  359. }
  360. internal class ForClause : ForLetClause
  361. {
  362. public ForClause ()
  363. {
  364. }
  365. public void Insert (int pos, ForSingleBody body)
  366. {
  367. List.Insert (pos, body);
  368. }
  369. public void Add (ForSingleBody body)
  370. {
  371. List.Add (body);
  372. }
  373. }
  374. internal class LetClause : ForLetClause
  375. {
  376. public LetClause ()
  377. {
  378. }
  379. public void Insert (int pos, LetSingleBody body)
  380. {
  381. List.Insert (pos, body);
  382. }
  383. public void Add (LetSingleBody body)
  384. {
  385. List.Add (body);
  386. }
  387. }
  388. internal abstract class ForLetSingleBody
  389. {
  390. XmlQualifiedName varName;
  391. SequenceType type;
  392. ExprSingle expr;
  393. public ForLetSingleBody (XmlQualifiedName varName, SequenceType type, ExprSingle expr)
  394. {
  395. this.varName = varName;
  396. this.type = type;
  397. this.expr = expr;
  398. }
  399. public XmlQualifiedName VarName {
  400. get { return varName; }
  401. }
  402. public SequenceType ReturnType {
  403. get { return type; }
  404. }
  405. public ExprSingle Expression {
  406. get { return expr; }
  407. set { expr = value; }
  408. }
  409. internal void CheckReference (XQueryASTCompiler compiler)
  410. {
  411. if (type != null)
  412. compiler.CheckSchemaType (type);
  413. expr.CheckReference (compiler);
  414. }
  415. }
  416. internal class ForSingleBody : ForLetSingleBody
  417. {
  418. public ForSingleBody (XmlQualifiedName varName, SequenceType type, XmlQualifiedName positionalVar, ExprSingle expr)
  419. : base (varName, type, expr)
  420. {
  421. this.positionalVar = positionalVar;
  422. }
  423. XmlQualifiedName positionalVar;
  424. public XmlQualifiedName PositionalVar {
  425. get { return positionalVar; }
  426. }
  427. }
  428. internal class LetSingleBody : ForLetSingleBody
  429. {
  430. public LetSingleBody (XmlQualifiedName varName, SequenceType type, ExprSingle expr)
  431. : base (varName, type, expr)
  432. {
  433. }
  434. }
  435. // QuantifiedExpr
  436. internal class QuantifiedExpr : ExprSingle
  437. {
  438. QuantifiedExprBodyList body;
  439. ExprSingle satisfies;
  440. bool every;
  441. public QuantifiedExpr (bool every, QuantifiedExprBodyList body, ExprSingle satisfies)
  442. {
  443. this.every = every;
  444. this.body = body;
  445. this.satisfies = satisfies;
  446. }
  447. public bool Every {
  448. get { return every; }
  449. }
  450. public QuantifiedExprBodyList BodyList {
  451. get { return body; }
  452. }
  453. public ExprSingle Satisfies {
  454. get { return satisfies; }
  455. set { satisfies = value; }
  456. }
  457. internal override void CheckReference (XQueryASTCompiler compiler)
  458. {
  459. foreach (QuantifiedExprBody one in body) {
  460. if (one.Type != null)
  461. compiler.CheckSchemaType (one.Type);
  462. one.Expression.CheckReference (compiler);
  463. }
  464. Satisfies.CheckReference (compiler);
  465. }
  466. #region CompileAndEvaluate
  467. internal override ExprSingle CompileCore (XQueryASTCompiler compiler)
  468. {
  469. Satisfies = Satisfies.Compile (compiler);
  470. for (int i = 0; i < BodyList.Count; i++) {
  471. BodyList [i].Expression = BodyList [i].Expression.Compile (compiler);
  472. if (BodyList [i].Type != null)
  473. compiler.CheckType (BodyList [i].Expression, BodyList [i].Type);
  474. }
  475. return this;
  476. }
  477. public override SequenceType StaticType {
  478. get { return SequenceType.Boolean; }
  479. }
  480. public override XPathSequence Evaluate (XPathSequence iter)
  481. {
  482. return new SingleItemIterator (EvaluateAsBoolean (iter) ? AtomicTrue : AtomicFalse, iter);
  483. }
  484. public override bool EvaluateAsBoolean (XPathSequence iter)
  485. {
  486. foreach (QuantifiedExprBody qb in BodyList) {
  487. XPathSequence seq = qb.Expression.Evaluate (iter);
  488. // FIXME: consider qb.Type
  489. // if (!qb.Type.IsValid (seq))
  490. // throw new XmlQueryException ("Quantified expression resulted in type promotion error.");
  491. iter.Context.PushVariable (qb.VarName, seq);
  492. }
  493. bool result = every;
  494. foreach (XPathItem item in iter) {
  495. if (satisfies.EvaluateAsBoolean (new SingleItemIterator (item, iter))) {
  496. if (!every) {
  497. result = true;
  498. break;
  499. }
  500. }
  501. else if (every) {
  502. result = false;
  503. break;
  504. }
  505. }
  506. for (int i = 0; i < BodyList.Count; i++)
  507. iter.Context.PopVariable ();
  508. return result;
  509. }
  510. #endregion
  511. }
  512. internal class QuantifiedExprBodyList : CollectionBase
  513. {
  514. public QuantifiedExprBodyList ()
  515. {
  516. }
  517. public void Add (QuantifiedExprBody body)
  518. {
  519. List.Add (body);
  520. }
  521. public void Insert (int pos, QuantifiedExprBody body)
  522. {
  523. List.Insert (pos, body);
  524. }
  525. public QuantifiedExprBody this [int i] {
  526. get { return (QuantifiedExprBody) List [i]; }
  527. }
  528. }
  529. internal class QuantifiedExprBody
  530. {
  531. private XmlQualifiedName varName;
  532. private SequenceType type;
  533. private ExprSingle expr;
  534. public QuantifiedExprBody (XmlQualifiedName varName,
  535. SequenceType type, ExprSingle expr)
  536. {
  537. this.varName = varName;
  538. this.type = type ;
  539. this.expr = expr;
  540. }
  541. public XmlQualifiedName VarName {
  542. get { return varName; }
  543. }
  544. public SequenceType Type {
  545. get { return type; }
  546. }
  547. public ExprSingle Expression {
  548. get { return expr; }
  549. set { expr = value; }
  550. }
  551. }
  552. // TypeswitchExpr
  553. internal class TypeswitchExpr : ExprSingle
  554. {
  555. ExprSequence switchExpr;
  556. CaseClauseList caseList;
  557. XmlQualifiedName defaultVarName;
  558. ExprSingle defaultReturn;
  559. public TypeswitchExpr (ExprSequence switchExpr, CaseClauseList caseList, XmlQualifiedName defaultVarName, ExprSingle defaultReturn)
  560. {
  561. this.switchExpr = switchExpr;
  562. this.caseList = caseList;
  563. this.defaultVarName = defaultVarName;
  564. this.defaultReturn = defaultReturn;
  565. }
  566. public ExprSequence SwitchExpr {
  567. get { return switchExpr; }
  568. }
  569. public CaseClauseList Cases {
  570. get { return caseList; }
  571. }
  572. public XmlQualifiedName DefaultVarName {
  573. get { return defaultVarName; }
  574. }
  575. public ExprSingle DefaultReturn {
  576. get { return defaultReturn; }
  577. set { defaultReturn = value; }
  578. }
  579. internal override void CheckReference (XQueryASTCompiler compiler)
  580. {
  581. switchExpr.CheckReference (compiler);
  582. foreach (CaseClause cc in caseList) {
  583. compiler.CheckSchemaType (cc.Type);
  584. cc.Expr.CheckReference (compiler);
  585. }
  586. defaultReturn.CheckReference (compiler);
  587. }
  588. #region CompileAndEvaluate
  589. internal override ExprSingle CompileCore (XQueryASTCompiler compiler)
  590. {
  591. for (int i = 0; i < SwitchExpr.Count; i++)
  592. SwitchExpr [i] = SwitchExpr [i].Compile (compiler);
  593. foreach (CaseClause cc in Cases)
  594. cc.Expr = cc.Expr.Compile (compiler);
  595. DefaultReturn = DefaultReturn.Compile (compiler);
  596. return this;
  597. }
  598. // FIXME: it can be optimized by checking all case clauses.
  599. public override SequenceType StaticType {
  600. get { return SequenceType.AnyType; }
  601. }
  602. public override XPathSequence Evaluate (XPathSequence iter)
  603. {
  604. // FIXME: should move to iterator?
  605. XPathSequence cond = new ExprSequenceIterator (iter, SwitchExpr);
  606. XPathSequence ret = null;
  607. foreach (CaseClause ccc in Cases) {
  608. if (ccc.Type.Matches (cond)) {
  609. if (ccc.VarName != XmlQualifiedName.Empty)
  610. iter.Context.PushVariable (ccc.VarName, cond);
  611. ret = ccc.Expr.Evaluate (iter);
  612. // FIXME: The design should make sure that in-scope variables are held on actual iteration.
  613. if (ccc.VarName != XmlQualifiedName.Empty)
  614. iter.Context.PopVariable ();
  615. return ret;
  616. }
  617. }
  618. if (DefaultVarName != XmlQualifiedName.Empty)
  619. iter.Context.PushVariable (DefaultVarName, cond);
  620. ret = DefaultReturn.Evaluate (iter);
  621. if (DefaultVarName != XmlQualifiedName.Empty)
  622. iter.Context.PopVariable ();
  623. return ret;
  624. }
  625. #endregion
  626. }
  627. internal class CaseClauseList : CollectionBase
  628. {
  629. public void Insert (int pos, CaseClause cc)
  630. {
  631. List.Insert (pos, cc);
  632. }
  633. public void Add (CaseClause cc)
  634. {
  635. List.Add (cc);
  636. }
  637. public CaseClause this [int i] {
  638. get { return (CaseClause) List [i]; }
  639. }
  640. }
  641. internal class CaseClause
  642. {
  643. public CaseClause (SequenceType type, ExprSingle expr, XmlQualifiedName varName)
  644. {
  645. this.type = type;
  646. this.expr = expr;
  647. this.varName = varName;
  648. }
  649. SequenceType type;
  650. ExprSingle expr;
  651. XmlQualifiedName varName;
  652. public SequenceType Type {
  653. get { return type; }
  654. }
  655. public ExprSingle Expr {
  656. get { return expr; }
  657. set { expr = value; }
  658. }
  659. public XmlQualifiedName VarName {
  660. get { return varName; }
  661. set { varName = value; }
  662. }
  663. }
  664. // IfExpr
  665. internal class IfExpr : ExprSingle
  666. {
  667. public IfExpr (ExprSequence condition, ExprSingle trueExpr, ExprSingle falseExpr)
  668. {
  669. this.condition = new ParenthesizedExpr (condition);
  670. this.trueExpr = trueExpr;
  671. this.falseExpr = falseExpr;
  672. }
  673. ExprSingle condition;
  674. ExprSingle trueExpr;
  675. ExprSingle falseExpr;
  676. public ExprSingle Condition {
  677. get { return condition; }
  678. set { condition = value; }
  679. }
  680. public ExprSingle TrueExpr {
  681. get { return trueExpr; }
  682. set { trueExpr = value; }
  683. }
  684. public ExprSingle FalseExpr {
  685. get { return falseExpr; }
  686. set { falseExpr = value; }
  687. }
  688. internal override void CheckReference (XQueryASTCompiler compiler)
  689. {
  690. condition.CheckReference (compiler);
  691. trueExpr.CheckReference (compiler);
  692. falseExpr.CheckReference (compiler);
  693. }
  694. #region CompileAndEvaluate
  695. SequenceType computedReturnType;
  696. internal override ExprSingle CompileCore (XQueryASTCompiler compiler)
  697. {
  698. // for (int i = 0; i < Condition.Count; i++)
  699. // Condition [i] = Condition [i].Compile (compiler);
  700. condition = condition.Compile (compiler);
  701. // FIXME: check if condition is constant, and returns trueExpr or falseExpr
  702. TrueExpr = TrueExpr.Compile (compiler);
  703. FalseExpr = FalseExpr.Compile (compiler);
  704. return this;
  705. }
  706. public override SequenceType StaticType {
  707. get {
  708. if (Context == null)
  709. return SequenceType.AnyType;
  710. if (computedReturnType == null)
  711. computedReturnType = SequenceType.ComputeCommonBase (TrueExpr.StaticType, FalseExpr.StaticType);
  712. return computedReturnType;
  713. }
  714. }
  715. public override XPathSequence Evaluate (XPathSequence iter)
  716. {
  717. // foreach (ExprSingle expr in Condition) {
  718. // if (expr.EvaluateAsBoolean (iter))
  719. // return TrueExpr.Evaluate (iter);
  720. // }
  721. if (condition.EvaluateAsBoolean (iter))
  722. return TrueExpr.Evaluate (iter);
  723. return FalseExpr.Evaluate (iter);
  724. }
  725. #endregion
  726. }
  727. // logical expr
  728. internal abstract class BinaryOperationExpr : ExprSingle
  729. {
  730. protected BinaryOperationExpr (ExprSingle left, ExprSingle right)
  731. {
  732. this.left = left;
  733. this.right = right;
  734. }
  735. ExprSingle left, right;
  736. public ExprSingle Left {
  737. get { return left; }
  738. set { left = value; }
  739. }
  740. public ExprSingle Right{
  741. get { return right; }
  742. set { right = value; }
  743. }
  744. internal override void CheckReference (XQueryASTCompiler compiler)
  745. {
  746. left.CheckReference (compiler);
  747. right.CheckReference (compiler);
  748. }
  749. #region CompileAndEvaluate
  750. internal override ExprSingle CompileCore (XQueryASTCompiler compiler)
  751. {
  752. Left = Left.Compile (compiler);
  753. Right = Right.Compile (compiler);
  754. return this;
  755. }
  756. #endregion
  757. }
  758. internal class OrExpr : BinaryOperationExpr
  759. {
  760. public OrExpr (ExprSingle left, ExprSingle right)
  761. : base (left, right)
  762. {
  763. }
  764. #region CompileAndEvaluate
  765. internal override ExprSingle CompileCore (XQueryASTCompiler compiler)
  766. {
  767. base.CompileCore (compiler);
  768. // FIXME: check constant value and return true or false
  769. return this;
  770. }
  771. public override SequenceType StaticType {
  772. get { return SequenceType.Boolean; }
  773. }
  774. public override bool EvaluateAsBoolean (XPathSequence iter)
  775. {
  776. return Left.EvaluateAsBoolean (iter) || Right.EvaluateAsBoolean (iter);
  777. }
  778. public override XPathSequence Evaluate (XPathSequence iter)
  779. {
  780. return new SingleItemIterator (EvaluateAsBoolean (iter) ?AtomicTrue : AtomicFalse, iter);
  781. }
  782. /*
  783. - compiler -
  784. return leftExprBool (context) || rightExprBool (context);
  785. */
  786. #endregion
  787. }
  788. internal class AndExpr : BinaryOperationExpr
  789. {
  790. public AndExpr (ExprSingle left, ExprSingle right)
  791. : base (left, right)
  792. {
  793. }
  794. #region CompileAndEvaluate
  795. internal override ExprSingle CompileCore (XQueryASTCompiler compiler)
  796. {
  797. base.CompileCore (compiler);
  798. // FIXME: check constant value and return true or false
  799. return this;
  800. }
  801. public override SequenceType StaticType {
  802. get { return SequenceType.Boolean; }
  803. }
  804. public override bool EvaluateAsBoolean (XPathSequence iter)
  805. {
  806. return Left.EvaluateAsBoolean (iter) && Right.EvaluateAsBoolean (iter);
  807. }
  808. public override XPathSequence Evaluate (XPathSequence iter)
  809. {
  810. return new SingleItemIterator (EvaluateAsBoolean (iter) ? AtomicTrue : AtomicFalse, iter);
  811. }
  812. /*
  813. - compiler -
  814. return leftExprBool (context) && rightExprBool (context);
  815. */
  816. #endregion
  817. }
  818. // TypeOperation expr
  819. internal abstract class TypeOperationExpr : ExprSingle
  820. {
  821. protected TypeOperationExpr (ExprSingle expr, SequenceType type)
  822. {
  823. this.expr = expr;
  824. this.type = type;
  825. }
  826. ExprSingle expr;
  827. SequenceType type;
  828. public ExprSingle Expr {
  829. get { return expr; }
  830. set { expr = value; }
  831. }
  832. public SequenceType TargetType {
  833. get { return type; }
  834. }
  835. internal override void CheckReference (XQueryASTCompiler compiler)
  836. {
  837. expr.CheckReference (compiler);
  838. compiler.CheckSchemaType (type);
  839. }
  840. }
  841. internal abstract class AtomicTypeOperationExpr : ExprSingle
  842. {
  843. protected AtomicTypeOperationExpr (ExprSingle expr, XmlTypeCode type, bool optional)
  844. {
  845. this.expr = expr;
  846. // this.typeCode = type;
  847. // this.optional = optional;
  848. this.targetType = SequenceType.Create (type, optional ? Occurence.Optional : Occurence.One);
  849. }
  850. ExprSingle expr;
  851. // XmlTypeCode typeCode;
  852. // bool optional;
  853. SequenceType targetType;
  854. internal ExprSingle Expr {
  855. get { return expr; }
  856. set { expr = value; }
  857. }
  858. /*
  859. public XmlTypeCode TypeCode {
  860. get { return typeCode; }
  861. }
  862. public bool Optional {
  863. get { return optional; }
  864. }
  865. */
  866. internal SequenceType TargetType {
  867. get { return targetType; }
  868. }
  869. internal override void CheckReference (XQueryASTCompiler compiler)
  870. {
  871. expr.CheckReference (compiler);
  872. }
  873. }
  874. internal class InstanceOfExpr : TypeOperationExpr
  875. {
  876. public InstanceOfExpr (ExprSingle expr, SequenceType type)
  877. : base (expr, type)
  878. {
  879. }
  880. #region CompileAndEvaluate
  881. internal override ExprSingle CompileCore (XQueryASTCompiler compiler)
  882. {
  883. Expr = Expr.Compile (compiler);
  884. // FIXME: check return type and if it never matches then return false
  885. return this;
  886. }
  887. public override SequenceType StaticType {
  888. get { return SequenceType.Boolean; }
  889. }
  890. public override bool EvaluateAsBoolean (XPathSequence iter)
  891. {
  892. bool occured = false;
  893. bool onlyOnce = (TargetType.Occurence == Occurence.One || TargetType.Occurence == Occurence.Optional);
  894. bool required = (TargetType.Occurence == Occurence.One || TargetType.Occurence == Occurence.OneOrMore);
  895. foreach (XPathItem item in iter) {
  896. if (occured && onlyOnce)
  897. return false;
  898. if (!TargetType.IsInstance (item))
  899. return false;
  900. }
  901. return occured || !required;
  902. }
  903. public override XPathSequence Evaluate (XPathSequence iter)
  904. {
  905. return new SingleItemIterator (EvaluateAsBoolean (iter) ? AtomicTrue : AtomicFalse, iter);
  906. }
  907. #endregion
  908. }
  909. internal class TreatExpr : TypeOperationExpr
  910. {
  911. public TreatExpr (ExprSingle expr, SequenceType type)
  912. : base (expr, type)
  913. {
  914. }
  915. #region CompileAndEvaluate
  916. internal override ExprSingle CompileCore (XQueryASTCompiler compiler)
  917. {
  918. Expr = Expr.Compile (compiler);
  919. // FIXME: check return type and if it never matches then return false
  920. return this;
  921. }
  922. public override SequenceType StaticType {
  923. get { return SequenceType.AnyType; }
  924. }
  925. public override XPathSequence Evaluate (XPathSequence iter)
  926. {
  927. if (TargetType.CanConvert (iter))
  928. return iter;
  929. else
  930. throw new XmlQueryException (String.Format ("Cannot treat as {1}", TargetType));
  931. }
  932. #endregion
  933. }
  934. internal class CastableExpr : AtomicTypeOperationExpr
  935. {
  936. public CastableExpr (ExprSingle expr, XmlTypeCode atomicType, bool optional)
  937. : base (expr, atomicType, optional)
  938. {
  939. }
  940. #region CompileAndEvaluate
  941. internal override ExprSingle CompileCore (XQueryASTCompiler compiler)
  942. {
  943. Expr = Expr.Compile (compiler);
  944. // FIXME: check return type and if it never matches then return boolean
  945. return this;
  946. }
  947. public override SequenceType StaticType {
  948. get { return SequenceType.Boolean; }
  949. }
  950. public override XPathSequence Evaluate (XPathSequence iter)
  951. {
  952. return new SingleItemIterator (new XPathAtomicValue (EvaluateAsBoolean (iter), XmlSchemaSimpleType.XsBoolean), iter);
  953. }
  954. public override bool EvaluateAsBoolean (XPathSequence iter)
  955. {
  956. bool occured = false;
  957. bool onlyOnce = (TargetType.Occurence == Occurence.One || TargetType.Occurence == Occurence.Optional);
  958. bool required = (TargetType.Occurence == Occurence.One || TargetType.Occurence == Occurence.OneOrMore);
  959. foreach (XPathItem item in iter) {
  960. if (occured && onlyOnce)
  961. return false;
  962. if (!TargetType.CanConvert (item))
  963. return false;
  964. }
  965. return occured || !required;
  966. }
  967. #endregion
  968. }
  969. internal class CastExpr : AtomicTypeOperationExpr
  970. {
  971. public CastExpr (ExprSingle expr, XmlTypeCode atomicType, bool optional)
  972. : base (expr, atomicType, optional)
  973. {
  974. }
  975. #region CompileAndEvaluate
  976. internal override ExprSingle CompileCore (XQueryASTCompiler compiler)
  977. {
  978. Expr = Expr.Compile (compiler);
  979. // FIXME: check return type and if it never matches then return boolean
  980. return this;
  981. }
  982. public override SequenceType StaticType {
  983. get { return TargetType; }
  984. }
  985. public override XPathSequence Evaluate (XPathSequence iter)
  986. {
  987. if (TargetType.CanConvert (iter))
  988. return new ConvertingIterator (iter, TargetType);
  989. else
  990. throw new XmlQueryException (String.Format ("Cannot cast as {1}", TargetType));
  991. }
  992. #endregion
  993. }
  994. // ComparisonExpr
  995. internal class ComparisonExpr : BinaryOperationExpr
  996. {
  997. public ComparisonExpr (ExprSingle left, ExprSingle right, ComparisonOperator oper)
  998. : base (left, right)
  999. {
  1000. }
  1001. #region CompileAndEvaluate
  1002. internal override ExprSingle CompileCore (XQueryASTCompiler compiler)
  1003. {
  1004. Left = Left.Compile (compiler);
  1005. Right = Right.Compile (compiler);
  1006. // FIXME: check return type and if it never matches then return boolean
  1007. return this;
  1008. }
  1009. public override SequenceType StaticType {
  1010. get { return SequenceType.Boolean; }
  1011. }
  1012. public override bool EvaluateAsBoolean (XPathSequence iter)
  1013. {
  1014. throw new NotImplementedException ();
  1015. }
  1016. public override XPathSequence Evaluate (XPathSequence iter)
  1017. {
  1018. return new SingleItemIterator (EvaluateAsBoolean (iter) ? AtomicTrue : AtomicFalse, iter);
  1019. }
  1020. #endregion
  1021. }
  1022. public enum ComparisonOperator {
  1023. ValueEQ,
  1024. ValueNE,
  1025. ValueLT,
  1026. ValueLE,
  1027. ValueGT,
  1028. ValueGE,
  1029. GeneralEQ,
  1030. GeneralNE,
  1031. GeneralLT,
  1032. GeneralLE,
  1033. GeneralGT,
  1034. GeneralGE,
  1035. NodeIs,
  1036. NodeFWD,
  1037. NodeBWD
  1038. }
  1039. // Range
  1040. internal class RangeExpr : BinaryOperationExpr
  1041. {
  1042. public RangeExpr (ExprSingle left, ExprSingle right)
  1043. : base (left, right)
  1044. {
  1045. }
  1046. #region CompileAndEvaluate
  1047. internal override ExprSingle CompileCore (XQueryASTCompiler compiler)
  1048. {
  1049. Left = Left.Compile (compiler);
  1050. Right = Right.Compile (compiler);
  1051. return this;
  1052. }
  1053. public override SequenceType StaticType {
  1054. get { return SequenceType.IntegerList; }
  1055. }
  1056. public override XPathSequence Evaluate (XPathSequence iter)
  1057. {
  1058. int start = Left.EvaluateAsInt (iter);
  1059. int end = Right.EvaluateAsInt (iter);
  1060. return new IntegerRangeIterator (iter, start, end);
  1061. }
  1062. public override void Serialize (XPathSequence iter)
  1063. {
  1064. int start = Left.EvaluateAsInt (iter);
  1065. int end = Right.EvaluateAsInt (iter);
  1066. for (int i = start; i <= end; i++) {
  1067. iter.Context.Writer.WriteValue (i);
  1068. if (i < end)
  1069. iter.Context.Writer.WriteWhitespace (" ");
  1070. }
  1071. }
  1072. #endregion
  1073. }
  1074. // arithmetic operation expr
  1075. public enum ArithmeticOperator {
  1076. Plus,
  1077. Minus,
  1078. Mul,
  1079. Div,
  1080. IDiv,
  1081. IMod
  1082. }
  1083. internal class ArithmeticOperationExpr : BinaryOperationExpr
  1084. {
  1085. public ArithmeticOperationExpr (ExprSingle left, ExprSingle right, ArithmeticOperator oper)
  1086. : base (left, right)
  1087. {
  1088. }
  1089. #region CompileAndEvaluate
  1090. internal override ExprSingle CompileCore (XQueryASTCompiler compiler)
  1091. {
  1092. Left = Left.Compile (compiler);
  1093. Right = Right.Compile (compiler);
  1094. return this;
  1095. }
  1096. // FIXME: It can be optimized by comparing l/r value types.
  1097. public override SequenceType StaticType {
  1098. get { return SequenceType.AnyType; }
  1099. }
  1100. public override XPathSequence Evaluate (XPathSequence iter)
  1101. {
  1102. XPathAtomicValue lvalue = Left.EvaluateAsAtomic (iter);
  1103. XPathAtomicValue rvalue = Right.EvaluateAsAtomic (iter);
  1104. throw new NotImplementedException ();
  1105. }
  1106. #endregion
  1107. }
  1108. internal class MinusExpr : ExprSingle
  1109. {
  1110. public MinusExpr (ExprSingle expr)
  1111. {
  1112. this.expr = expr;
  1113. }
  1114. ExprSingle expr;
  1115. public ExprSingle Expr {
  1116. get { return expr; }
  1117. set { expr = value; }
  1118. }
  1119. internal override void CheckReference (XQueryASTCompiler compiler)
  1120. {
  1121. expr.CheckReference (compiler);
  1122. }
  1123. #region CompileAndEvaluate
  1124. internal override ExprSingle CompileCore (XQueryASTCompiler compiler)
  1125. {
  1126. Expr = Expr.Compile (compiler);
  1127. return this;
  1128. }
  1129. public override SequenceType StaticType {
  1130. get { return Expr.StaticType; }
  1131. }
  1132. public override XPathSequence Evaluate (XPathSequence iter)
  1133. {
  1134. throw new NotImplementedException ();
  1135. }
  1136. #endregion
  1137. }
  1138. // aggregation expr
  1139. public enum AggregationType {
  1140. Union,
  1141. Intersect,
  1142. Except
  1143. }
  1144. internal class GroupExpr : BinaryOperationExpr
  1145. {
  1146. public GroupExpr (ExprSingle left, ExprSingle right, AggregationType aggrType)
  1147. : base (left, right)
  1148. {
  1149. this.aggrType = aggrType;
  1150. }
  1151. AggregationType aggrType;
  1152. public AggregationType AggregationType {
  1153. get { return aggrType; }
  1154. }
  1155. #region CompileAndEvaluate
  1156. internal override ExprSingle CompileCore (XQueryASTCompiler compiler)
  1157. {
  1158. Left = Left.Compile (compiler);
  1159. Right = Right.Compile (compiler);
  1160. return this;
  1161. }
  1162. // FIXME: It can be optimized by comparing l/r value types.
  1163. public override SequenceType StaticType {
  1164. get { return SequenceType.AnyType; }
  1165. }
  1166. // only applicable against node-sets
  1167. public override XPathSequence Evaluate (XPathSequence iter)
  1168. {
  1169. XPathSequence lvalue = Left.EvaluateOrdered (iter);
  1170. XPathSequence rvalue = Right.EvaluateOrdered (iter);
  1171. /*
  1172. TBD (yield earlier node, skipping one of the same nodes)
  1173. - or -
  1174. TBD (yield earlier node, skipping non-intersection nodes)
  1175. - or -
  1176. TBD (yield earlier node, skipping both of the same nodes)
  1177. */
  1178. throw new NotImplementedException ();
  1179. }
  1180. #endregion
  1181. }
  1182. // validate expr
  1183. internal class ValidateExpr : ExprSingle
  1184. {
  1185. XmlSchemaContentProcessing schemaMode;
  1186. ExprSequence expr;
  1187. public ValidateExpr (XmlSchemaContentProcessing schemaMode, ExprSequence expr)
  1188. {
  1189. this.schemaMode = schemaMode;
  1190. this.expr = expr;
  1191. }
  1192. public ExprSequence Expr {
  1193. get { return expr; }
  1194. }
  1195. public XmlSchemaContentProcessing SchemaMode {
  1196. get { return schemaMode; }
  1197. }
  1198. internal override void CheckReference (XQueryASTCompiler compiler)
  1199. {
  1200. expr.CheckReference (compiler);
  1201. }
  1202. #region CompileAndEvaluate
  1203. internal override ExprSingle CompileCore (XQueryASTCompiler compiler)
  1204. {
  1205. for (int i = 0; i < expr.Count; i++)
  1206. expr [i] = expr [i].Compile (compiler);
  1207. return this;
  1208. }
  1209. public override SequenceType StaticType {
  1210. get { return SequenceType.AnyType; }
  1211. }
  1212. public override XPathSequence Evaluate (XPathSequence iter)
  1213. {
  1214. // TBD (see 3.13).
  1215. throw new NotImplementedException ();
  1216. }
  1217. #endregion
  1218. }
  1219. // Path expr
  1220. internal abstract class PathExpr : ExprSingle
  1221. {
  1222. }
  1223. // '/'
  1224. internal class PathRootExpr : PathExpr
  1225. {
  1226. public PathRootExpr ()
  1227. {
  1228. }
  1229. internal override void CheckReference (XQueryASTCompiler compiler)
  1230. {
  1231. }
  1232. #region CompileAndEvaluate
  1233. internal override ExprSingle CompileCore (XQueryASTCompiler compiler)
  1234. {
  1235. return this;
  1236. }
  1237. public override SequenceType StaticType {
  1238. get { return SequenceType.Document; }
  1239. }
  1240. public override XPathSequence Evaluate (XPathSequence iter)
  1241. {
  1242. if (!iter.MoveNext ())
  1243. return new XPathEmptySequence (iter);
  1244. XPathNavigator nav = iter.Current as XPathNavigator;
  1245. if (nav == null)
  1246. return new XPathEmptySequence (iter);
  1247. nav = nav.Clone ();
  1248. nav.MoveToRoot ();
  1249. return new SingleItemIterator (nav, iter);
  1250. }
  1251. #endregion
  1252. }
  1253. internal abstract class PathStepExpr : PathExpr
  1254. {
  1255. ExprSingle first;
  1256. ExprSingle next;
  1257. public PathStepExpr (ExprSingle first, ExprSingle next)
  1258. {
  1259. this.first = first;
  1260. this.next = next;
  1261. }
  1262. public ExprSingle First {
  1263. get { return first; }
  1264. set { first = value; }
  1265. }
  1266. public ExprSingle Next {
  1267. get { return next; }
  1268. set { next = value; }
  1269. }
  1270. internal override void CheckReference (XQueryASTCompiler compiler)
  1271. {
  1272. first.CheckReference (compiler);
  1273. next.CheckReference (compiler);
  1274. }
  1275. internal override ExprSingle CompileCore (XQueryASTCompiler compiler)
  1276. {
  1277. first = first.Compile (compiler);
  1278. next = next.Compile (compiler);
  1279. return this;
  1280. }
  1281. }
  1282. // 'foo/bar'
  1283. internal class PathSlashExpr : PathStepExpr
  1284. {
  1285. public PathSlashExpr (ExprSingle first, ExprSingle next)
  1286. : base (first, next)
  1287. {
  1288. }
  1289. #region CompileAndEvaluate
  1290. // FIXME: It can be optimized by comparing l/r value types.
  1291. public override SequenceType StaticType {
  1292. get { return SequenceType.Node; }
  1293. }
  1294. public override XPathSequence Evaluate (XPathSequence iter)
  1295. {
  1296. return new PathStepIterator (First.Evaluate (iter), this);
  1297. }
  1298. #endregion
  1299. }
  1300. // 'foo//bar'
  1301. internal class PathSlash2Expr : PathStepExpr
  1302. {
  1303. public PathSlash2Expr (ExprSingle first, ExprSingle next)
  1304. : base (first, next)
  1305. {
  1306. }
  1307. #region CompileAndEvaluate
  1308. // FIXME: It can be optimized by comparing l/r value types.
  1309. public override SequenceType StaticType {
  1310. get { return SequenceType.Node; }
  1311. }
  1312. public override XPathSequence Evaluate (XPathSequence iter)
  1313. {
  1314. // return new DescendantPathIterator (iter, this);
  1315. return new PathStepIterator (
  1316. new DescendantOrSelfIterator (First.Evaluate (iter)), this);
  1317. }
  1318. #endregion
  1319. }
  1320. internal class AxisStepExpr : PathExpr
  1321. {
  1322. static AxisStepExpr parentStep;
  1323. static AxisStepExpr ()
  1324. {
  1325. parentStep = new AxisStepExpr (XPathAxis.Parent, null);
  1326. }
  1327. public static AxisStepExpr ParentStep {
  1328. get { return parentStep; }
  1329. }
  1330. public AxisStepExpr (XPathAxis axis, XPath2NodeTest test)
  1331. {
  1332. this.axis = axis;
  1333. if (test == null)
  1334. nameTest = XmlQualifiedName.Empty;
  1335. else {
  1336. if (test.NameTest != null)
  1337. this.nameTest = test.NameTest;
  1338. else
  1339. this.kindTest = test.KindTest;
  1340. }
  1341. }
  1342. XPathAxis axis;
  1343. XmlQualifiedName nameTest;
  1344. KindTest kindTest;
  1345. public XPathAxis Axis {
  1346. get { return axis; }
  1347. }
  1348. public XmlQualifiedName NameTest {
  1349. get { return nameTest; }
  1350. set { nameTest = value; }
  1351. }
  1352. public KindTest KindTest {
  1353. get { return kindTest; }
  1354. set { kindTest = value; }
  1355. }
  1356. internal override void CheckReference (XQueryASTCompiler compiler)
  1357. {
  1358. if (KindTest != null)
  1359. KindTest.CheckReference (compiler);
  1360. }
  1361. #region CompileAndEvaluate
  1362. internal override ExprSingle CompileCore (XQueryASTCompiler compiler)
  1363. {
  1364. if (KindTest != null)
  1365. KindTest.Compile (compiler);
  1366. return this;
  1367. }
  1368. public override SequenceType StaticType {
  1369. get {
  1370. switch (Axis.AxisType) {
  1371. case XPathAxisType.Attribute:
  1372. return SequenceType.Attribute;
  1373. case XPathAxisType.Namespace:
  1374. return SequenceType.Namespace;
  1375. }
  1376. // FIXME: we can more filtering by KindTest
  1377. return SequenceType.Node;
  1378. }
  1379. }
  1380. public override XPathSequence Evaluate (XPathSequence iter)
  1381. {
  1382. XPathSequence argIter = null;
  1383. switch (Axis.AxisType) {
  1384. case XPathAxisType.Child:
  1385. argIter = new ChildIterator (iter); break;
  1386. case XPathAxisType.Descendant:
  1387. argIter = new DescendantIterator (iter); break;
  1388. case XPathAxisType.Attribute:
  1389. argIter = new AttributeIterator (iter); break;
  1390. case XPathAxisType.Self:
  1391. argIter = new SingleItemIterator (iter.Current, iter); break;
  1392. case XPathAxisType.DescendantOrSelf:
  1393. argIter = new DescendantOrSelfIterator (iter); break;
  1394. case XPathAxisType.FollowingSibling:
  1395. argIter = new FollowingSiblingIterator (iter); break;
  1396. case XPathAxisType.Following:
  1397. argIter = new FollowingIterator (iter); break;
  1398. case XPathAxisType.Parent:
  1399. argIter = new ParentIterator (iter); break;
  1400. case XPathAxisType.Ancestor:
  1401. argIter = new AncestorIterator (iter); break;
  1402. case XPathAxisType.PrecedingSibling:
  1403. argIter = new PrecedingSiblingIterator (iter); break;
  1404. case XPathAxisType.Preceding:
  1405. argIter = new PrecedingIterator (iter); break;
  1406. case XPathAxisType.AncestorOrSelf:
  1407. argIter = new AncestorOrSelfIterator (iter); break;
  1408. case XPathAxisType.Namespace: // only applicable under XPath 2.0: not XQuery 1.0
  1409. argIter = new NamespaceIterator (iter); break;
  1410. }
  1411. return new AxisIterator (argIter, this);
  1412. }
  1413. internal bool Matches (XPathNavigator nav)
  1414. {
  1415. if (nameTest != null)
  1416. return nameTest == XmlQualifiedName.Empty ||
  1417. ((nameTest.Name == nav.LocalName || nameTest.Name == "*") &&
  1418. (nameTest.Namespace == nav.NamespaceURI || nameTest.Namespace == "*"));
  1419. else
  1420. return kindTest.Matches (nav);
  1421. }
  1422. #endregion
  1423. }
  1424. internal class FilterStepExpr : PathExpr
  1425. {
  1426. public FilterStepExpr (ExprSingle expr, PredicateList predicates)
  1427. {
  1428. this.expr = expr;
  1429. this.predicates = predicates;
  1430. }
  1431. ExprSingle expr;
  1432. PredicateList predicates;
  1433. public ExprSingle Expr {
  1434. get { return expr; }
  1435. set { expr = value; }
  1436. }
  1437. public PredicateList Predicates {
  1438. get { return predicates; }
  1439. }
  1440. internal override void CheckReference (XQueryASTCompiler compiler)
  1441. {
  1442. expr.CheckReference (compiler);
  1443. foreach (ExprSequence seq in predicates)
  1444. seq.CheckReference (compiler);
  1445. }
  1446. #region CompileAndEvaluate
  1447. internal override ExprSingle CompileCore (XQueryASTCompiler compiler)
  1448. {
  1449. Expr = Expr.Compile (compiler);
  1450. foreach (ExprSequence seq in Predicates)
  1451. for (int i = 0; i < seq.Count; i++)
  1452. seq [i] = seq [i].Compile (compiler);
  1453. return this;
  1454. }
  1455. public override SequenceType StaticType {
  1456. get { return Expr.StaticType; }
  1457. }
  1458. public override XPathSequence Evaluate (XPathSequence iter)
  1459. {
  1460. return new FilteredIterator (iter, this);
  1461. }
  1462. #endregion
  1463. }
  1464. // predicates == exprsequence list == list of list of exprsingle
  1465. internal class PredicateList : CollectionBase
  1466. {
  1467. public void Add (ExprSequence expr)
  1468. {
  1469. List.Add (expr);
  1470. }
  1471. public void Insert (int pos, ExprSequence expr)
  1472. {
  1473. List.Insert (pos, expr);
  1474. }
  1475. public ExprSequence this [int i] {
  1476. get { return (ExprSequence) List [i]; }
  1477. }
  1478. }
  1479. internal class XPath2NodeTest
  1480. {
  1481. public XPath2NodeTest (XmlQualifiedName nameTest)
  1482. {
  1483. this.NameTest = nameTest;
  1484. }
  1485. public XPath2NodeTest (KindTest kindTest)
  1486. {
  1487. this.KindTest = kindTest;
  1488. }
  1489. public XmlQualifiedName NameTest;
  1490. public KindTest KindTest;
  1491. }
  1492. internal class EnclosedExpr : ExprSingle
  1493. {
  1494. ExprSequence expr;
  1495. public EnclosedExpr (ExprSequence expr)
  1496. {
  1497. this.expr = expr;
  1498. }
  1499. public ExprSequence Expr {
  1500. get { return expr; }
  1501. }
  1502. internal override void CheckReference (XQueryASTCompiler compiler)
  1503. {
  1504. expr.CheckReference (compiler);
  1505. }
  1506. #region CompileAndEvaluate
  1507. internal override ExprSingle CompileCore (XQueryASTCompiler compiler)
  1508. {
  1509. if (Expr.Count == 0)
  1510. return Expr [0].Compile (compiler);
  1511. for (int i = 0; i < Expr.Count; i++)
  1512. Expr [i] = Expr [i].Compile (compiler);
  1513. return this;
  1514. }
  1515. // FIXME: can be optimized by checking all items in Expr
  1516. public override SequenceType StaticType {
  1517. get { return SequenceType.AnyType; }
  1518. }
  1519. public override XPathSequence Evaluate (XPathSequence iter)
  1520. {
  1521. return new ExprSequenceIterator (iter, Expr);
  1522. }
  1523. #endregion
  1524. }
  1525. // PrimaryExpr
  1526. internal abstract class PrimaryExpr : ExprSingle
  1527. {
  1528. internal override void CheckReference (XQueryASTCompiler compiler)
  1529. {
  1530. }
  1531. #region CompileAndEvaluate
  1532. internal override ExprSingle CompileCore (XQueryASTCompiler compiler)
  1533. {
  1534. return this;
  1535. }
  1536. public override XPathSequence Evaluate (XPathSequence iter)
  1537. {
  1538. return new SingleItemIterator (EvaluateAsAtomic (iter), iter);
  1539. }
  1540. #endregion
  1541. }
  1542. internal class StringLiteralExpr : PrimaryExpr
  1543. {
  1544. string literal;
  1545. public StringLiteralExpr (string literal)
  1546. {
  1547. this.literal = literal;
  1548. }
  1549. public string Literal {
  1550. get { return literal; }
  1551. }
  1552. #region CompileAndEvaluate
  1553. XmlSchemaSimpleType stringType = XmlSchemaType.GetBuiltInSimpleType (new XmlQualifiedName ("string", XmlSchema.Namespace));
  1554. public override SequenceType StaticType {
  1555. get { return SequenceType.AtomicString; }
  1556. }
  1557. public override string EvaluateAsString (XPathSequence iter)
  1558. {
  1559. return Literal;
  1560. }
  1561. public override XPathAtomicValue EvaluateAsAtomic (XPathSequence iter)
  1562. {
  1563. return new XPathAtomicValue (Literal, stringType);
  1564. }
  1565. #endregion
  1566. }
  1567. internal class DecimalLiteralExpr : PrimaryExpr
  1568. {
  1569. decimal value;
  1570. public DecimalLiteralExpr (decimal value)
  1571. {
  1572. this.value = value;
  1573. }
  1574. public decimal Value {
  1575. get { return value; }
  1576. }
  1577. #region CompileAndEvaluate
  1578. XmlSchemaSimpleType decimalType = XmlSchemaType.GetBuiltInSimpleType (new XmlQualifiedName ("decimal", XmlSchema.Namespace));
  1579. public override SequenceType StaticType {
  1580. get { return SequenceType.Decimal; }
  1581. }
  1582. public override XPathAtomicValue EvaluateAsAtomic (XPathSequence iter)
  1583. {
  1584. return new XPathAtomicValue (Value, decimalType);
  1585. }
  1586. #endregion
  1587. }
  1588. internal class DoubleLiteralExpr : PrimaryExpr
  1589. {
  1590. double value;
  1591. public DoubleLiteralExpr (double value)
  1592. {
  1593. this.value = value;
  1594. }
  1595. public double Value {
  1596. get { return value; }
  1597. }
  1598. #region CompileAndEvaluate
  1599. XmlSchemaSimpleType doubleType = XmlSchemaType.GetBuiltInSimpleType (new XmlQualifiedName ("double", XmlSchema.Namespace));
  1600. public override SequenceType StaticType {
  1601. get { return SequenceType.Double; }
  1602. }
  1603. public override XPathAtomicValue EvaluateAsAtomic (XPathSequence iter)
  1604. {
  1605. return new XPathAtomicValue (Value, doubleType);
  1606. }
  1607. #endregion
  1608. }
  1609. internal class VariableReferenceExpr : PrimaryExpr
  1610. {
  1611. XmlQualifiedName varName;
  1612. public VariableReferenceExpr (XmlQualifiedName varName)
  1613. {
  1614. this.varName = varName;
  1615. }
  1616. public XmlQualifiedName VariableName {
  1617. get { return varName; }
  1618. }
  1619. // FIXME: variable name must be stacked in any area
  1620. // whereever variables are defined.
  1621. internal override void CheckReference (XQueryASTCompiler compiler)
  1622. {
  1623. compiler.CheckVariableName (varName);
  1624. }
  1625. #region CompileAndEvaluate
  1626. internal override ExprSingle CompileCore (XQueryASTCompiler compiler)
  1627. {
  1628. // FIXME: try to resolve static context variable and return the actual value expression
  1629. return this;
  1630. }
  1631. public override SequenceType StaticType {
  1632. get { return SequenceType.AnyType; }
  1633. }
  1634. public override XPathSequence Evaluate (XPathSequence iter)
  1635. {
  1636. XPathSequence variable = iter.Context.ResolveVariable (VariableName, iter);
  1637. // FIXME: if Evaluate() accepts XPathSequence, then XPathSequence must be public class (to make IXPath2Variable public).
  1638. return variable;
  1639. }
  1640. #endregion
  1641. }
  1642. internal class ParenthesizedExpr : PrimaryExpr
  1643. {
  1644. ExprSequence expr;
  1645. public ParenthesizedExpr (ExprSequence expr)
  1646. {
  1647. this.expr = expr;
  1648. }
  1649. ExprSequence Expr {
  1650. get { return expr; }
  1651. }
  1652. #region CompileAndEvaluate
  1653. internal override ExprSingle CompileCore (XQueryASTCompiler compiler)
  1654. {
  1655. if (Expr.Count == 1)
  1656. return Expr [0].Compile (compiler);
  1657. for (int i = 0; i < Expr.Count; i++)
  1658. Expr [i] = Expr [i].Compile (compiler);
  1659. return this;
  1660. }
  1661. // FIXME: can be optimized by checking all items in Expr
  1662. public override SequenceType StaticType {
  1663. get { return SequenceType.AnyType; }
  1664. }
  1665. public override XPathSequence Evaluate (XPathSequence iter)
  1666. {
  1667. return new ExprSequenceIterator (iter, Expr);
  1668. }
  1669. #endregion
  1670. }
  1671. // "."
  1672. internal class ContextItemExpr : PrimaryExpr
  1673. {
  1674. public ContextItemExpr ()
  1675. {
  1676. }
  1677. #region CompileAndEvaluate
  1678. internal override ExprSingle CompileCore (XQueryASTCompiler compiler)
  1679. {
  1680. return this;
  1681. }
  1682. public override SequenceType StaticType {
  1683. get { return SequenceType.AnyType; }
  1684. }
  1685. public override XPathSequence Evaluate (XPathSequence iter)
  1686. {
  1687. return new SingleItemIterator (iter.Context.CurrentItem, iter);
  1688. }
  1689. #endregion
  1690. }
  1691. internal abstract class FunctionCallExprBase : PrimaryExpr
  1692. {
  1693. XmlQualifiedName name;
  1694. ExprSequence args;
  1695. public FunctionCallExprBase (XmlQualifiedName name, ExprSequence args)
  1696. {
  1697. if (args == null)
  1698. throw new ArgumentNullException (String.Format ("Function argument expressions for {0} is null.", name));
  1699. this.name = name;
  1700. this.args = args;
  1701. }
  1702. public XmlQualifiedName Name {
  1703. get { return name; }
  1704. }
  1705. public ExprSequence Args {
  1706. get { return args; }
  1707. }
  1708. internal override void CheckReference (XQueryASTCompiler compiler)
  1709. {
  1710. compiler.CheckFunctionName (name);
  1711. }
  1712. #region CompileAndEvaluate
  1713. /*
  1714. internal static FunctionCallExpr Create (
  1715. XmlQualifiedName name,
  1716. ExprSingle [] args,
  1717. XQueryStaticContext ctx)
  1718. {
  1719. switch (name.Namespace) {
  1720. case XQueryFunction.Namespace:
  1721. switch (name.Name) {
  1722. case "node-name":
  1723. return new FnNodeNameCall (ctx, args);
  1724. case "nilled":
  1725. return new FnNilledCall (ctx, args);
  1726. case "string":
  1727. return new FnStringCall (ctx, args);
  1728. case "data":
  1729. return new FnDataCall (ctx, args);
  1730. case "base-uri":
  1731. return new FnBaseUriCall (ctx, args);
  1732. case "document-uri":
  1733. return new FnDocumentUriCall (ctx, args);
  1734. case "error":
  1735. return new FnErrorCall (ctx, args);
  1736. case "trace":
  1737. return new FnTraceCall (ctx, args);
  1738. case "abs":
  1739. return new FnAbsCall (ctx, args);
  1740. case "ceiling":
  1741. return new FnCeilingCall (ctx, args);
  1742. case "floor":
  1743. return new FnFloorCall (ctx, args);
  1744. case "round":
  1745. return new FnRoundCall (ctx, args);
  1746. case "round-half-to-even":
  1747. return new FnRoundHalfToEvenCall (ctx, args);
  1748. case "codepoints-to-string":
  1749. return new FnCodepointsToStringCall (ctx, args);
  1750. case "string-to-codepoints":
  1751. return new FnStringCallToCodepointsCall (ctx, args);
  1752. }
  1753. goto default;
  1754. case XmlSchema.XdtNamespace:
  1755. case XmlSchema.Namespace:
  1756. XmlSchemaType type = XmlSchemaType.GetBuiltInSimpleType (name);
  1757. if (type != null)
  1758. return new AtomicConstructorCall (ctx, SequenceType.Create (type, Occurence.One), args);
  1759. type = XmlSchemaType.GetBuiltInComplexType (name);
  1760. if (type == null)
  1761. goto default;
  1762. return null;
  1763. default:
  1764. XQueryFunction func = ctx.CompileContext.InEffectFunctions [name];
  1765. if (func != null)
  1766. return new CustomFunctionCallExpression (ctx, args, func);
  1767. return null;
  1768. }
  1769. }
  1770. */
  1771. internal void CheckArguments (XQueryASTCompiler compiler)
  1772. {
  1773. if (args.Count < MinArgs || args.Count > MaxArgs)
  1774. // FIXME: add more info
  1775. throw new XmlQueryCompileException (String.Format ("{0} is invalid for the number of {1} function argument. MinArgs = {2}, MaxArgs = {3}.", args.Count, name, MinArgs, MaxArgs));
  1776. }
  1777. public abstract int MinArgs { get; }
  1778. public abstract int MaxArgs { get; }
  1779. #endregion
  1780. }
  1781. // This class is used only in AST
  1782. internal class FunctionCallExpr : FunctionCallExprBase
  1783. {
  1784. public FunctionCallExpr (XmlQualifiedName name, ExprSequence args)
  1785. : base (name, args)
  1786. {
  1787. }
  1788. #region CompileAndEvaluate
  1789. internal override ExprSingle CompileCore (XQueryASTCompiler compiler)
  1790. {
  1791. // resolve function
  1792. return new CustomFunctionCallExpr (Args, compiler.ResolveFunction (Name)).Compile (compiler);
  1793. }
  1794. public override XPathSequence Evaluate (XPathSequence iter)
  1795. {
  1796. throw new InvalidOperationException ("XQuery internal error. Should not happen.");
  1797. }
  1798. public override SequenceType StaticType {
  1799. get { throw new InvalidOperationException ("XQuery internal error. Should not happen."); }
  1800. }
  1801. public override int MinArgs {
  1802. get { throw new InvalidOperationException ("XQuery internal error. Should not happen."); }
  1803. }
  1804. public override int MaxArgs {
  1805. get { throw new InvalidOperationException ("XQuery internal error. Should not happen."); }
  1806. }
  1807. #endregion
  1808. }
  1809. #region CompileAndEvaluate
  1810. // It is instantiated per function call expression.
  1811. // (e.g. the example below contains 4 FunctionCallExpression instances:
  1812. // "replace(node-name (node-before(/*)), 'foo', node-name($var))"
  1813. internal class CustomFunctionCallExpr : FunctionCallExprBase
  1814. {
  1815. public CustomFunctionCallExpr (ExprSequence args, XQueryFunction function)
  1816. : base (function.Name, args)
  1817. {
  1818. this.function = function;
  1819. }
  1820. XQueryFunction function;
  1821. public XQueryFunction Function {
  1822. get { return function; }
  1823. }
  1824. public override int MinArgs {
  1825. get { return function.MinArgs; }
  1826. }
  1827. public override int MaxArgs {
  1828. get { return function.MaxArgs; }
  1829. }
  1830. public override SequenceType StaticType {
  1831. get { return function.ReturnType; }
  1832. }
  1833. internal override ExprSingle CompileCore (XQueryASTCompiler compiler)
  1834. {
  1835. CheckArguments (compiler);
  1836. for (int i = 0; i < Args.Count; i++)
  1837. Args [i] = Args [i].Compile (compiler);
  1838. return this;
  1839. }
  1840. public override XPathSequence Evaluate (XPathSequence iter)
  1841. {
  1842. return Function.Evaluate (iter, Args);
  1843. }
  1844. // FIXME: add all overrides that delegates to XQueryFunction
  1845. }
  1846. #endregion
  1847. // Ordered / Unordered
  1848. internal class OrderSpecifiedExpr : ExprSingle
  1849. {
  1850. bool ordered;
  1851. ExprSequence expr;
  1852. public OrderSpecifiedExpr (ExprSequence expr, bool ordered)
  1853. {
  1854. this.ordered = ordered;
  1855. this.expr = expr;
  1856. }
  1857. public ExprSequence Expr {
  1858. get { return expr; }
  1859. }
  1860. public bool Ordered {
  1861. get { return ordered; }
  1862. }
  1863. internal override void CheckReference (XQueryASTCompiler compiler)
  1864. {
  1865. expr.CheckReference (compiler);
  1866. }
  1867. #region CompileAndEvaluate
  1868. public override SequenceType StaticType {
  1869. // FIXME: could be optimized by checking all the expressions
  1870. get { return SequenceType.AnyType; }
  1871. }
  1872. public override bool RequireSorting {
  1873. get { return Ordered; }
  1874. }
  1875. internal override ExprSingle CompileCore (XQueryASTCompiler compiler)
  1876. {
  1877. for (int i = 0; i < Expr.Count; i++)
  1878. Expr [i] = Expr [i].Compile (compiler);
  1879. return this;
  1880. }
  1881. public override XPathSequence Evaluate (XPathSequence iter)
  1882. {
  1883. throw new NotImplementedException ();
  1884. }
  1885. #endregion
  1886. }
  1887. }
  1888. #endif