2 * Copyright 2005 Frerich Raabe <raabe@kde.org>
3 * Copyright (C) 2006 Apple Computer, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
27 #ifndef XPathPredicate_h
28 #define XPathPredicate_h
30 #include "core/xml/XPathExpressionNode.h"
31 #include "core/xml/XPathValue.h"
37 class Number FINAL : public Expression {
39 explicit Number(double);
40 virtual void trace(Visitor*) OVERRIDE;
43 virtual Value evaluate() const OVERRIDE;
44 virtual Value::Type resultType() const OVERRIDE { return Value::NumberValue; }
49 class StringExpression FINAL : public Expression {
51 explicit StringExpression(const String&);
52 virtual void trace(Visitor*) OVERRIDE;
55 virtual Value evaluate() const OVERRIDE;
56 virtual Value::Type resultType() const OVERRIDE { return Value::StringValue; }
61 class Negative FINAL : public Expression {
63 virtual Value evaluate() const OVERRIDE;
64 virtual Value::Type resultType() const OVERRIDE { return Value::NumberValue; }
67 class NumericOp FINAL : public Expression {
70 OP_Add, OP_Sub, OP_Mul, OP_Div, OP_Mod
72 NumericOp(Opcode, PassOwnPtrWillBeRawPtr<Expression> lhs, PassOwnPtrWillBeRawPtr<Expression> rhs);
75 virtual Value evaluate() const OVERRIDE;
76 virtual Value::Type resultType() const OVERRIDE { return Value::NumberValue; }
81 class EqTestOp FINAL : public Expression {
83 enum Opcode { OpcodeEqual, OpcodeNotEqual, OpcodeGreaterThan, OpcodeLessThan, OpcodeGreaterOrEqual, OpcodeLessOrEqual };
84 EqTestOp(Opcode, PassOwnPtrWillBeRawPtr<Expression> lhs, PassOwnPtrWillBeRawPtr<Expression> rhs);
85 virtual Value evaluate() const OVERRIDE;
88 virtual Value::Type resultType() const OVERRIDE { return Value::BooleanValue; }
89 bool compare(const Value&, const Value&) const;
94 class LogicalOp FINAL : public Expression {
96 enum Opcode { OP_And, OP_Or };
97 LogicalOp(Opcode, PassOwnPtrWillBeRawPtr<Expression> lhs, PassOwnPtrWillBeRawPtr<Expression> rhs);
100 virtual Value::Type resultType() const OVERRIDE { return Value::BooleanValue; }
101 bool shortCircuitOn() const;
102 virtual Value evaluate() const OVERRIDE;
107 class Union FINAL : public Expression {
109 virtual Value evaluate() const OVERRIDE;
110 virtual Value::Type resultType() const OVERRIDE { return Value::NodeSetValue; }
113 class Predicate FINAL : public NoBaseWillBeGarbageCollected<Predicate> {
114 WTF_MAKE_NONCOPYABLE(Predicate); WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED;
115 DECLARE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(Predicate);
117 explicit Predicate(PassOwnPtrWillBeRawPtr<Expression>);
118 void trace(Visitor*);
120 bool evaluate() const;
121 bool isContextPositionSensitive() const { return m_expr->isContextPositionSensitive() || m_expr->resultType() == Value::NumberValue; }
122 bool isContextSizeSensitive() const { return m_expr->isContextSizeSensitive(); }
125 OwnPtrWillBeMember<Expression> m_expr;
131 #endif // XPathPredicate_h