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