
//  -*- c++ -*-

#ifndef XPATH_EXPRESSION_H
#define XPATH_EXPRESSION_H

#include <qvaluelist.h>
#include <dom/dom_node.h>

#include <xpath/xpath_value.h>

namespace XPath {

class QueryState;

/**
 * Represents an XPath location path.
 */
class LocationPath : public XPathNode
{
public:
    enum LocationPathType {
	Relative, Absolute, AbbrevRelative, AbbrevAbsolute
    };

private:
    LocationPathType ptype;
};

/**
 * Represents an XPath variable reference.
 */
class VariableRef : public XPathNode
{
public:
};

/**
 * Represents an XPath binary operator.
 */
class BinaryOp : public XPathNode
{
public:
    enum BinaryOpType {
	NullBinaryOp,
	Or, And, Equality,
	LessThan, GreaterThan, LessThanEqual, GreaterThanEqual,
	Plus, Minus, Mul, Div, Mod,
	Union
    };

    BinaryOp();
    BinaryOp( const BinaryOp &node );
    BinaryOp( ushort bop );
    virtual ~BinaryOp();

    virtual Value *evaluate( QueryState *state );

    virtual QString name() const;
    virtual QString qstring() const;

private:
    ushort op;
    XPathNode lexpr;
    XPathNode rexpr;
};

/**
 * Represents an XPath unary operator.
 */
class UnaryOp : public XPathNode
{
public:
    enum UnaryOpType {
	UnaryMinus
    };

private:
    UnaryOpType optype;
    XPathNode expr;
};

/**
 * Represents an XPath node test.
 */
class NodeTest : public XPathNode
{
public:
    enum NodeTestId {
	AnyName, NCName, QName,
	CommentNode, TextNode, ProcessInstructNode, NodeNode
    };

private:
    ushort id;
};

/**
 * Represents an XPath function call.
 */
class FunctionCall : public XPathNode
{
public:
    enum Functions {
	FunctionNull,

	// node-set functions
	FunctionLast, FunctionPosition, FunctionCount,
	FunctionId, FunctionLocalName, FunctionNamespaceURI, FunctionName,

	// string functions
	FunctionString,	FunctionConcat, FunctionStartsWith, FunctionContains,
	FunctionSubStringBefore, FunctionSubStringAfter, FunctionSubString,
	FunctionStringLength, FunctionNormalizeSpace, FunctionTranslate,

	// boolean functions
	FunctionBoolean, FunctionNot, FunctionTrue, FunctionFalse, FunctionLang,

	// number functions
	FunctionNumber, FunctionSum, FunctionFloor, FunctionCeiling, FunctionRound,

	// Reserves space for XPath. (XSLT needs to add new funcs).
	FunctionLastReserved = 256
    };

    FunctionCall();
    FunctionCall( const FunctionCall &node );
    FunctionCall( ushort fid );
    virtual ~FunctionCall();

    virtual Value *evaluate( QueryState *state );

    virtual QString name() const;
    virtual QString qstring() const;

private:
    ushort id;
    QValueList<XPathNode> args;
};

/**
 * Represents a reference to an XPath axis.
 */
class Axis : public XPathNode
{
public:
    enum Id {
	NullAxis,
	Child, Descendent, Parent, Ancestor,
	FollowingSibling, PrecedingSibling,
	Following, Preceding,
	Attribute, Namespace,
	Self, DescendentOrSelf, AncestorOrSelf
    };

    Axis();
    Axis( const Axis &node );
    Axis( ushort fid );
    virtual ~Axis();

    virtual Value *evaluate( QueryState *state );

    virtual QString name() const;
    virtual QString qstring() const;

private:
    ushort id;
};

}; // namespace XPath

#endif // XPATH_EXPRESSION_H

// Local Variables:
// c-basic-offset: 4
// End:

