#include <kdebug.h>

#include "xpath_node.h"

namespace XPath {

//
// XPathNode
//

XPathNode::XPathNode()
{
    type = NullNode;
}

XPathNode::XPathNode( const XPathNode &n )
{
    type = n.type;
}

XPathNode::XPathNode( XPathNode::NodeType nt )
{
    type = nt;
}

XPathNode::~XPathNode()
{

}

QString XPathNode::qstring() const
{
    if ( type == NullNode )
	return QString("XPathNode::Null");

    QString s("XPathNode::type=%1");
    return s.arg( (uint) type );
}

//
// AxisNode
//

Axis::Axis()
    : XPathNode( AxisNode ),
      id( NullAxis )
{
}

Axis::Axis( const Axis &node )
    : XPathNode( AxisNode ),
      id( node.id )
{
}

Axis::Axis( ushort fid )
    : XPathNode( AxisNode ),
      id( fid )
{
}

Axis::~Axis()
{
}

QString Axis::name() const
{
    const uint names_count = 15;
    const char *names[] = {
	"null_axis",
	"child", "descendent", "parent", "ancestor",
	"following-sibling", "preceding-sibling",
	"following", "preceding",
	"attribute", "namespace",
	"self", "descendent-or-self", "ancestor-or-self",
	"INTERNAL_ERROR"
    };

    if ( id < names_count )
	return QString("%1::").arg( names[id] );
    else
	return QString("axis::id=%1)").arg(id);
}

QString Axis::qstring() const
{
    return name();
}

//
// BinaryOpNode
//

BinaryOp::BinaryOp()
    : XPathNode( BinaryOpNode ),
      op( NullBinaryOp )
{
}

BinaryOp::BinaryOp( const BinaryOp &node )
    : XPathNode( BinaryOpNode ),
      op( node.op )
{
}

BinaryOp::BinaryOp( ushort bop )
    : XPathNode( BinaryOpNode ),
      op( bop )
{
}

BinaryOp::~BinaryOp()
{
}

QString BinaryOp::name() const
{
    const uint names_count = 14;
    const char *names[] = {
	"null-operator",
	"or", "and", "equality",
	"less-than", "greater-than", "less-than-equal", "greater-than-equal",
	"plus", "minus", "mul", "div", "mod",

	"INTERNAL_ERROR"
    };

    if ( op < names_count )
	return QString("operator %1").arg( names[op] );
    else
	return QString("binop::id=%1)").arg(op);
}

QString BinaryOp::qstring() const
{
    return name();
}

//
// FunctionCallNode
//

FunctionCall::FunctionCall()
    : XPathNode( FunctionCallNode ),
      id( NullFunction )
{
}

FunctionCall::FunctionCall( const FunctionCall &node )
    : XPathNode( FunctionCallNode ),
      id( node.id )
{
}

FunctionCall::FunctionCall( ushort fid )
    : XPathNode( FunctionCallNode ),
      id( fid )
{
}

FunctionCall::~FunctionCall()
{
}

QString FunctionCall::name() const
{
    const uint names_count = 29;
    const char *names[] = {
	"null_function",
	"last", "position", "count",
	"id", "local-name", "namespace-uri", "name",
	"string", "concat", "startswith", "contains",
	"substring-before", "substring-after", "substring",
	"string-length", "normalize-space", "translate",
	"boolean", "not", "true", "false", "lang",
	"number", "sum", "floor", "ceiling", "round", "INTERNAL_ERROR"
    };

    if ( id < names_count )
	return QString("%1()").arg( names[id] );
    else
	return QString("function(id=%1)").arg(id);
}

QString FunctionCall::qstring() const
{
    return name();
}

}; // namespace XPath


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