#ifndef XPathExpressionNode_h
#define XPathExpressionNode_h
#include "core/dom/Node.h"
#include "core/xml/XPathValue.h"
#include "wtf/HashMap.h"
#include "wtf/Vector.h"
#include "wtf/text/StringHash.h"
namespace WebCore {
namespace XPath {
struct EvaluationContext {
WTF_MAKE_FAST_ALLOCATED;
public:
RefPtr<Node> node;
unsigned long size;
unsigned long position;
HashMap<String, String> variableBindings;
bool hadTypeConversionError;
};
class ParseNode {
public:
virtual ~ParseNode() { }
};
class Expression : public ParseNode {
WTF_MAKE_NONCOPYABLE(Expression); WTF_MAKE_FAST_ALLOCATED;
public:
static EvaluationContext& evaluationContext();
Expression();
virtual ~Expression();
virtual Value evaluate() const = 0;
void addSubExpression(PassOwnPtr<Expression> expr)
{
m_isContextNodeSensitive |= expr->m_isContextNodeSensitive;
m_isContextPositionSensitive |= expr->m_isContextPositionSensitive;
m_isContextSizeSensitive |= expr->m_isContextSizeSensitive;
m_subExpressions.append(expr);
}
bool isContextNodeSensitive() const { return m_isContextNodeSensitive; }
bool isContextPositionSensitive() const { return m_isContextPositionSensitive; }
bool isContextSizeSensitive() const { return m_isContextSizeSensitive; }
void setIsContextNodeSensitive(bool value) { m_isContextNodeSensitive = value; }
void setIsContextPositionSensitive(bool value) { m_isContextPositionSensitive = value; }
void setIsContextSizeSensitive(bool value) { m_isContextSizeSensitive = value; }
virtual Value::Type resultType() const = 0;
protected:
unsigned subExprCount() const { return m_subExpressions.size(); }
Expression* subExpr(unsigned i) { return m_subExpressions[i].get(); }
const Expression* subExpr(unsigned i) const { return m_subExpressions[i].get(); }
private:
Vector<OwnPtr<Expression> > m_subExpressions;
bool m_isContextNodeSensitive;
bool m_isContextPositionSensitive;
bool m_isContextSizeSensitive;
};
}
}
#endif