File indexing completed on 2024-04-28 11:39:42

0001 /*
0002  * step.h - Copyright 2005 Frerich Raabe <raabe@kde.org>
0003  *
0004  * Redistribution and use in source and binary forms, with or without
0005  * modification, are permitted provided that the following conditions
0006  * are met:
0007  *
0008  * 1. Redistributions of source code must retain the above copyright
0009  *    notice, this list of conditions and the following disclaimer.
0010  * 2. Redistributions in binary form must reproduce the above copyright
0011  *    notice, this list of conditions and the following disclaimer in the
0012  *    documentation and/or other materials provided with the distribution.
0013  *
0014  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
0015  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0016  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
0017  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
0018  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
0019  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0020  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0021  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0022  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
0023  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0024  */
0025 #ifndef STEP_H
0026 #define STEP_H
0027 
0028 #include "predicate.h"
0029 #include "util.h"
0030 
0031 #include <QList>
0032 
0033 #include <dom/dom_string.h>
0034 
0035 namespace DOM
0036 {
0037 class NodeImpl;
0038 }
0039 
0040 namespace khtml
0041 {
0042 namespace XPath
0043 {
0044 
0045 class Step
0046 {
0047 public:
0048     enum AxisType {
0049         AncestorAxis = 1, AncestorOrSelfAxis, AttributeAxis,
0050         ChildAxis, DescendantAxis, DescendantOrSelfAxis,
0051         FollowingAxis, FollowingSiblingAxis, NamespaceAxis,
0052         ParentAxis, PrecedingAxis, PrecedingSiblingAxis,
0053         SelfAxis
0054     };
0055 
0056     static QString axisAsString(AxisType axis);
0057 
0058     Step();
0059     Step(AxisType axis,
0060          const DOM::DOMString &nodeTest,
0061          const QList<Predicate *> &predicates = QList<Predicate *>());
0062     ~Step();
0063 
0064     DomNodeList evaluate(DOM::NodeImpl *context) const;
0065 
0066     void optimize();
0067     QString dump() const;
0068 
0069 private:
0070     DomNodeList nodesInAxis(DOM::NodeImpl *context) const;
0071     DomNodeList nodeTestMatches(DOM::NodeImpl *ctx, const DomNodeList &nodes) const;
0072     DOM::DOMString namespaceFromNodetest(const DOM::DOMString &nodeTest) const;
0073     unsigned int primaryNodeType(AxisType axis) const;
0074 
0075     // Original axis + nodetest specification
0076     AxisType m_axis;
0077     DOM::DOMString m_nodeTest;
0078 
0079     enum CompileState {
0080         NotCompiled,
0081         CompiledForHTML,
0082         CompiledForXML
0083     };
0084 
0085     mutable CompileState m_compileState;
0086 
0087     void compileNodeTest(bool htmlCompat) const;
0088 
0089     // Compiled nodetest information. We do this jit'ish due to the
0090     // case sensitivity mess.
0091     mutable enum {
0092         NT_Star,        // *
0093         NT_LocalName,   // NCName
0094         NT_Namespace,   // NCName:*
0095         NT_QName,       // Prefix:LocalName
0096         NT_Comment,     // 'comment'
0097         NT_Text,        // 'text'
0098         NT_PI,          // 'processing-instruction'
0099         NT_AnyNode,     // 'node'
0100         NT_PI_Lit       // 'processing-instruction' '(' Literal ')'
0101     } m_nodeTestType;
0102     mutable DOM::LocalName     m_localName;
0103     mutable DOM::NamespaceName m_namespace;
0104     mutable DOM::DOMString m_piInfo;
0105 
0106     QList<Predicate *> m_predicates;
0107 };
0108 
0109 } // namespace XPath
0110 
0111 } // namespace khtml
0112 
0113 #endif // STEP_H
0114