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