1/* 2 * Copyright 2005 Frerich Raabe <raabe@kde.org> 3 * Copyright (C) 2006, 2013 Apple Inc. All rights reserved. 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 XPathPredicate_h 28#define XPathPredicate_h 29 30#include "XPathExpressionNode.h" 31 32namespace WebCore { 33 34 namespace XPath { 35 36 class Number final : public Expression { 37 public: 38 explicit Number(double); 39 40 private: 41 virtual Value evaluate() const override; 42 virtual Value::Type resultType() const override { return Value::NumberValue; } 43 44 Value m_value; 45 }; 46 47 class StringExpression final : public Expression { 48 public: 49 explicit StringExpression(String&&); 50 51 private: 52 virtual Value evaluate() const override; 53 virtual Value::Type resultType() const override { return Value::StringValue; } 54 55 Value m_value; 56 }; 57 58 class Negative final : public Expression { 59 public: 60 explicit Negative(std::unique_ptr<Expression>); 61 62 private: 63 virtual Value evaluate() const override; 64 virtual Value::Type resultType() const override { return Value::NumberValue; } 65 }; 66 67 class NumericOp final : public Expression { 68 public: 69 enum Opcode { OP_Add, OP_Sub, OP_Mul, OP_Div, OP_Mod }; 70 NumericOp(Opcode, std::unique_ptr<Expression> lhs, std::unique_ptr<Expression> rhs); 71 72 private: 73 virtual Value evaluate() const override; 74 virtual Value::Type resultType() const override { return Value::NumberValue; } 75 76 Opcode m_opcode; 77 }; 78 79 class EqTestOp final : public Expression { 80 public: 81 enum Opcode { OP_EQ, OP_NE, OP_GT, OP_LT, OP_GE, OP_LE }; 82 EqTestOp(Opcode, std::unique_ptr<Expression> lhs, std::unique_ptr<Expression> rhs); 83 virtual Value evaluate() const override; 84 85 private: 86 virtual Value::Type resultType() const override { return Value::BooleanValue; } 87 bool compare(const Value&, const Value&) const; 88 89 Opcode m_opcode; 90 }; 91 92 class LogicalOp final : public Expression { 93 public: 94 enum Opcode { OP_And, OP_Or }; 95 LogicalOp(Opcode, std::unique_ptr<Expression> lhs, std::unique_ptr<Expression> rhs); 96 97 private: 98 virtual Value::Type resultType() const override { return Value::BooleanValue; } 99 bool shortCircuitOn() const; 100 virtual Value evaluate() const override; 101 102 Opcode m_opcode; 103 }; 104 105 class Union final : public Expression { 106 public: 107 Union(std::unique_ptr<Expression>, std::unique_ptr<Expression>); 108 109 private: 110 virtual Value evaluate() const override; 111 virtual Value::Type resultType() const override { return Value::NodeSetValue; } 112 }; 113 114 bool evaluatePredicate(const Expression&); 115 bool predicateIsContextPositionSensitive(const Expression&); 116 117 } 118 119} 120 121#endif // XPathPredicate_h 122