2005-11-02 10:42:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2005-11-02 10:34:13 +03:00
|
|
|
|
2005-11-02 20:34:14 +03:00
|
|
|
#include "txExpr.h"
|
2005-11-02 10:40:48 +03:00
|
|
|
#include "txIXPathContext.h"
|
2005-11-02 10:41:43 +03:00
|
|
|
#include "txNodeSet.h"
|
2005-11-02 10:34:13 +03:00
|
|
|
|
|
|
|
//-------------/
|
|
|
|
//- UnionExpr -/
|
|
|
|
//-------------/
|
|
|
|
|
2005-11-02 10:36:56 +03:00
|
|
|
//-----------------------------/
|
2005-11-02 10:36:37 +03:00
|
|
|
//- Virtual methods from Expr -/
|
2005-11-02 10:36:56 +03:00
|
|
|
//-----------------------------/
|
2005-11-02 10:34:13 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Evaluates this Expr based on the given context node and processor state
|
|
|
|
* @param context the context node for evaluation of this Expr
|
|
|
|
* @param ps the ContextState containing the stack information needed
|
|
|
|
* for evaluation
|
|
|
|
* @return the result of the evaluation
|
|
|
|
**/
|
2005-11-02 10:40:48 +03:00
|
|
|
nsresult
|
|
|
|
UnionExpr::evaluate(txIEvalContext* aContext, txAExprResult** aResult)
|
2005-11-02 10:37:48 +03:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*aResult = nullptr;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<txNodeSet> nodes;
|
2005-11-02 10:40:48 +03:00
|
|
|
nsresult rv = aContext->recycler()->getNodeSet(getter_AddRefs(nodes));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2005-11-02 10:37:48 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t i, len = mExpressions.Length();
|
2006-12-13 00:20:15 +03:00
|
|
|
for (i = 0; i < len; ++i) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<txAExprResult> exprResult;
|
2006-12-13 00:20:15 +03:00
|
|
|
rv = mExpressions[i]->evaluate(aContext, getter_AddRefs(exprResult));
|
2005-11-02 10:40:48 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (exprResult->getResultType() != txAExprResult::NODESET) {
|
|
|
|
//XXX ErrorReport: report nonnodeset error
|
|
|
|
return NS_ERROR_XSLT_NODESET_EXPECTED;
|
2005-11-02 10:34:13 +03:00
|
|
|
}
|
2005-11-02 10:41:43 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<txNodeSet> resultSet, ownedSet;
|
2007-07-08 11:08:04 +04:00
|
|
|
resultSet = static_cast<txNodeSet*>
|
|
|
|
(static_cast<txAExprResult*>(exprResult));
|
2012-07-30 18:20:58 +04:00
|
|
|
exprResult = nullptr;
|
2005-11-02 10:41:43 +03:00
|
|
|
rv = aContext->recycler()->
|
|
|
|
getNonSharedNodeSet(resultSet, getter_AddRefs(ownedSet));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = nodes->addAndTransfer(ownedSet);
|
2005-11-02 10:40:48 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2005-11-02 10:34:13 +03:00
|
|
|
}
|
|
|
|
|
2005-11-02 10:40:48 +03:00
|
|
|
*aResult = nodes;
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
|
|
|
|
return NS_OK;
|
2005-11-02 10:34:13 +03:00
|
|
|
} //-- evaluate
|
|
|
|
|
2006-11-10 23:31:59 +03:00
|
|
|
Expr::ExprType
|
|
|
|
UnionExpr::getType()
|
|
|
|
{
|
|
|
|
return UNION_EXPR;
|
|
|
|
}
|
|
|
|
|
2006-12-13 00:20:15 +03:00
|
|
|
TX_IMPL_EXPR_STUBS_LIST(UnionExpr, NODESET_RESULT, mExpressions)
|
2006-01-26 04:50:30 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2006-01-26 04:50:30 +03:00
|
|
|
UnionExpr::isSensitiveTo(ContextSensitivity aContext)
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t i, len = mExpressions.Length();
|
2006-12-13 00:20:15 +03:00
|
|
|
for (i = 0; i < len; ++i) {
|
|
|
|
if (mExpressions[i]->isSensitiveTo(aContext)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2006-01-26 04:50:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2006-01-26 04:50:30 +03:00
|
|
|
}
|
|
|
|
|
2005-11-02 10:42:10 +03:00
|
|
|
#ifdef TX_TO_STRING
|
|
|
|
void
|
|
|
|
UnionExpr::toString(nsAString& dest)
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t i;
|
2006-12-13 00:20:15 +03:00
|
|
|
for (i = 0; i < mExpressions.Length(); ++i) {
|
|
|
|
if (i > 0)
|
2005-11-02 10:42:33 +03:00
|
|
|
dest.AppendLiteral(" | ");
|
2006-12-13 00:20:15 +03:00
|
|
|
mExpressions[i]->toString(dest);
|
2005-11-02 10:34:13 +03:00
|
|
|
}
|
2005-11-02 10:42:10 +03:00
|
|
|
}
|
|
|
|
#endif
|