1 /* 2 * step.h - Copyright 2005 Frerich Raabe <raabe@kde.org> 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 #ifndef STEP_H 26 #define STEP_H 27 28 #include "predicate.h" 29 #include "util.h" 30 31 #include <QList> 32 33 #include <dom/dom_string.h> 34 35 namespace DOM 36 { 37 class NodeImpl; 38 } 39 40 namespace khtml 41 { 42 namespace XPath 43 { 44 45 class Step 46 { 47 public: 48 enum AxisType { 49 AncestorAxis = 1, AncestorOrSelfAxis, AttributeAxis, 50 ChildAxis, DescendantAxis, DescendantOrSelfAxis, 51 FollowingAxis, FollowingSiblingAxis, NamespaceAxis, 52 ParentAxis, PrecedingAxis, PrecedingSiblingAxis, 53 SelfAxis 54 }; 55 56 static QString axisAsString(AxisType axis); 57 58 Step(); 59 Step(AxisType axis, 60 const DOM::DOMString &nodeTest, 61 const QList<Predicate *> &predicates = QList<Predicate *>()); 62 ~Step(); 63 64 DomNodeList evaluate(DOM::NodeImpl *context) const; 65 66 void optimize(); 67 QString dump() const; 68 69 private: 70 DomNodeList nodesInAxis(DOM::NodeImpl *context) const; 71 DomNodeList nodeTestMatches(DOM::NodeImpl *ctx, const DomNodeList &nodes) const; 72 DOM::DOMString namespaceFromNodetest(const DOM::DOMString &nodeTest) const; 73 unsigned int primaryNodeType(AxisType axis) const; 74 75 // Original axis + nodetest specification 76 AxisType m_axis; 77 DOM::DOMString m_nodeTest; 78 79 enum CompileState { 80 NotCompiled, 81 CompiledForHTML, 82 CompiledForXML 83 }; 84 85 mutable CompileState m_compileState; 86 87 void compileNodeTest(bool htmlCompat) const; 88 89 // Compiled nodetest information. We do this jit'ish due to the 90 // case sensitivity mess. 91 mutable enum { 92 NT_Star, // * 93 NT_LocalName, // NCName 94 NT_Namespace, // NCName:* 95 NT_QName, // Prefix:LocalName 96 NT_Comment, // 'comment' 97 NT_Text, // 'text' 98 NT_PI, // 'processing-instruction' 99 NT_AnyNode, // 'node' 100 NT_PI_Lit // 'processing-instruction' '(' Literal ')' 101 } m_nodeTestType; 102 mutable DOM::LocalName m_localName; 103 mutable DOM::NamespaceName m_namespace; 104 mutable DOM::DOMString m_piInfo; 105 106 QList<Predicate *> m_predicates; 107 }; 108 109 } // namespace XPath 110 111 } // namespace khtml 112 113 #endif // STEP_H 114 115