1 /* 2 * Copyright (C) 2005 Frerich Raabe <raabe@kde.org> 3 * Copyright (C) 2006, 2009 Apple Inc. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27 #ifndef XPathStep_h 28 #define XPathStep_h 29 30 #if ENABLE(XPATH) 31 32 #include "Node.h" 33 #include "XPathExpressionNode.h" 34 #include "XPathNodeSet.h" 35 36 namespace WebCore { 37 38 namespace XPath { 39 40 class Predicate; 41 42 class Step : public ParseNode, public Noncopyable { 43 public: 44 enum Axis { 45 AncestorAxis, AncestorOrSelfAxis, AttributeAxis, 46 ChildAxis, DescendantAxis, DescendantOrSelfAxis, 47 FollowingAxis, FollowingSiblingAxis, NamespaceAxis, 48 ParentAxis, PrecedingAxis, PrecedingSiblingAxis, 49 SelfAxis 50 }; 51 52 class NodeTest : public FastAllocBase { 53 public: 54 enum Kind { 55 TextNodeTest, CommentNodeTest, ProcessingInstructionNodeTest, AnyNodeTest, NameTest 56 }; 57 NodeTest(Kind kind)58 NodeTest(Kind kind) : m_kind(kind) {} NodeTest(Kind kind,const String & data)59 NodeTest(Kind kind, const String& data) : m_kind(kind), m_data(data) {} NodeTest(Kind kind,const String & data,const String & namespaceURI)60 NodeTest(Kind kind, const String& data, const String& namespaceURI) : m_kind(kind), m_data(data), m_namespaceURI(namespaceURI) {} 61 kind()62 Kind kind() const { return m_kind; } data()63 const AtomicString& data() const { return m_data; } namespaceURI()64 const AtomicString& namespaceURI() const { return m_namespaceURI; } mergedPredicates()65 Vector<Predicate*>& mergedPredicates() { return m_mergedPredicates; } mergedPredicates()66 const Vector<Predicate*>& mergedPredicates() const { return m_mergedPredicates; } 67 68 private: 69 Kind m_kind; 70 AtomicString m_data; 71 AtomicString m_namespaceURI; 72 73 // When possible, we merge some or all predicates with node test for better performance. 74 Vector<Predicate*> m_mergedPredicates; 75 }; 76 77 Step(Axis, const NodeTest& nodeTest, const Vector<Predicate*>& predicates = Vector<Predicate*>()); 78 ~Step(); 79 80 void optimize(); 81 82 void evaluate(Node* context, NodeSet&) const; 83 axis()84 Axis axis() const { return m_axis; } nodeTest()85 const NodeTest& nodeTest() const { return m_nodeTest; } 86 87 private: 88 friend void optimizeStepPair(Step*, Step*, bool&); 89 bool predicatesAreContextListInsensitive() const; 90 91 void parseNodeTest(const String&); 92 void nodesInAxis(Node* context, NodeSet&) const; 93 String namespaceFromNodetest(const String& nodeTest) const; 94 95 Axis m_axis; 96 NodeTest m_nodeTest; 97 Vector<Predicate*> m_predicates; 98 }; 99 100 void optimizeStepPair(Step*, Step*, bool& dropSecondStep); 101 } 102 103 } 104 105 #endif // ENABLE(XPATH) 106 107 #endif // XPathStep_h 108