Value EqTestOp::evaluate() const
{
    Value lhs(subExpr(0)->evaluate());
    Value rhs(subExpr(1)->evaluate());

    return compare(lhs, rhs);
}
Esempio n. 2
0
Value EqTestOp::evaluate() const
{
    Value lhs(subExpr(0)->evaluate());
    Value rhs(subExpr(1)->evaluate());

    return BOOL_TO_VALUE_CAST compare(lhs, rhs);
}
Esempio n. 3
0
Value Union::evaluate() const
{
    Value lhsResult = subExpr(0)->evaluate();
    Value rhs = subExpr(1)->evaluate();
    
    NodeSet& resultSet = lhsResult.modifiableNodeSet();
    const NodeSet& rhsNodes = rhs.toNodeSet();
    
    HashSet<Node*> nodes;
    for (size_t i = 0; i < resultSet.size(); ++i)
        nodes
Value LogicalOp::evaluate() const
{
    Value lhs(subExpr(0)->evaluate());

    // This is not only an optimization, http://www.w3.org/TR/xpath
    // dictates that we must do short-circuit evaluation
    bool lhsBool = lhs.toBoolean();
    if (lhsBool == shortCircuitOn())
        return lhsBool;

    return subExpr(1)->evaluate().toBoolean();
}
Value NumericOp::evaluate() const
{
    Value lhs(subExpr(0)->evaluate());
    Value rhs(subExpr(1)->evaluate());
    
    double leftVal = lhs.toNumber();
    double rightVal = rhs.toNumber();

    switch (m_opcode) {
        case OP_Add:
            return leftVal + rightVal;
        case OP_Sub:
            return leftVal - rightVal;
        case OP_Mul:
            return leftVal * rightVal;
        case OP_Div:
            return leftVal / rightVal;
        case OP_Mod:
            return fmod(leftVal, rightVal);
    }
    ASSERT_NOT_REACHED();
    return 0.0;
}
Value Union::evaluate() const
{
    Value lhsResult = subExpr(0)->evaluate();
    Value rhs = subExpr(1)->evaluate();
    
    NodeSet& resultSet = lhsResult.modifiableNodeSet();
    const NodeSet& rhsNodes = rhs.toNodeSet();
    
    HashSet<Node*> nodes;
    for (size_t i = 0; i < resultSet.size(); ++i)
        nodes.add(resultSet[i]);
    
    for (size_t i = 0; i < rhsNodes.size(); ++i) {
        Node* node = rhsNodes[i];
        if (nodes.add(node).second)
            resultSet.append(node);
    }

    // It is also possible to use merge sort to avoid making the result unsorted;
    // but this would waste the time in cases when order is not important.
    resultSet.markSorted(false);
    return lhsResult;
}
Esempio n. 7
0
Object* Parser::parseSubExpression1()
{
	std::auto_ptr<Object> result;

	if(hasTokens() && peekToken().getType() == T_LPAREN)
	{
		getToken();
		result.reset(parseExpression());
		if(!hasTokens() || peekToken().getType() != T_RPAREN)
			throw ParserSyntaxException(getToken(), "Expected closing parentheses!");
		getToken();
	}

	else if(hasTokens() && peekToken().getType() == T_LARROW)
	{
		std::auto_ptr<Sequence> seq(new Sequence());
		Token tok = getToken();
		seq->setLineNumber(tok.getLineNumber());
		seq->setColumnNumber(tok.getColumnNumber());

		while(hasTokens() && peekToken().getType() != T_RARROW)
		{
			std::auto_ptr<Object> subExpr(parseExpression());
			seq->pushObject(subExpr.release());
			if(hasTokens() && peekToken().getType() != T_COMMA)
				break;
			getToken();
		}

		if(!hasTokens() || peekToken().getType() != T_RARROW)
			throw ParserSyntaxException(getToken(), "Expected right arrow to end sequence!");
		getToken();

		result.reset(seq.release());
	}

	else
		result.reset(parseValue());

	return parseSubExpression1a(result.release());
}
Value Negative::evaluate() const
{
    Value p(subExpr(0)->evaluate());
    return -p.toNumber();
}