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