2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "txExpr.h"
|
|
|
|
#include "txIXPathContext.h"
|
|
|
|
#include "txNodeSet.h"
|
|
|
|
|
|
|
|
//-------------/
|
|
|
|
//- UnionExpr -/
|
|
|
|
//-------------/
|
|
|
|
|
|
|
|
//-----------------------------/
|
|
|
|
//- Virtual methods from Expr -/
|
|
|
|
//-----------------------------/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
**/
|
|
|
|
nsresult
|
|
|
|
UnionExpr::evaluate(txIEvalContext* aContext, txAExprResult** aResult)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
*aResult = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsRefPtr<txNodeSet> nodes;
|
|
|
|
nsresult rv = aContext->recycler()->getNodeSet(getter_AddRefs(nodes));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t i, len = mExpressions.Length();
|
2007-03-22 10:30:00 -07:00
|
|
|
for (i = 0; i < len; ++i) {
|
|
|
|
nsRefPtr<txAExprResult> exprResult;
|
|
|
|
rv = mExpressions[i]->evaluate(aContext, getter_AddRefs(exprResult));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (exprResult->getResultType() != txAExprResult::NODESET) {
|
|
|
|
//XXX ErrorReport: report nonnodeset error
|
|
|
|
return NS_ERROR_XSLT_NODESET_EXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<txNodeSet> resultSet, ownedSet;
|
2007-07-08 00:08:04 -07:00
|
|
|
resultSet = static_cast<txNodeSet*>
|
|
|
|
(static_cast<txAExprResult*>(exprResult));
|
2012-07-30 07:20:58 -07:00
|
|
|
exprResult = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = aContext->recycler()->
|
|
|
|
getNonSharedNodeSet(resultSet, getter_AddRefs(ownedSet));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = nodes->addAndTransfer(ownedSet);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
*aResult = nodes;
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
} //-- evaluate
|
|
|
|
|
|
|
|
Expr::ExprType
|
|
|
|
UnionExpr::getType()
|
|
|
|
{
|
|
|
|
return UNION_EXPR;
|
|
|
|
}
|
|
|
|
|
|
|
|
TX_IMPL_EXPR_STUBS_LIST(UnionExpr, NODESET_RESULT, mExpressions)
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
UnionExpr::isSensitiveTo(ContextSensitivity aContext)
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t i, len = mExpressions.Length();
|
2007-03-22 10:30:00 -07:00
|
|
|
for (i = 0; i < len; ++i) {
|
|
|
|
if (mExpressions[i]->isSensitiveTo(aContext)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef TX_TO_STRING
|
|
|
|
void
|
|
|
|
UnionExpr::toString(nsAString& dest)
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t i;
|
2007-03-22 10:30:00 -07:00
|
|
|
for (i = 0; i < mExpressions.Length(); ++i) {
|
|
|
|
if (i > 0)
|
|
|
|
dest.AppendLiteral(" | ");
|
|
|
|
mExpressions[i]->toString(dest);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|