2005-11-02 07:42:05 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 11:12:37 +00: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 07:34:13 +00:00
|
|
|
|
2006-04-06 06:12:25 +00:00
|
|
|
#include "txExpr.h"
|
2017-10-02 22:05:19 +00:00
|
|
|
#include "nsAtom.h"
|
2005-11-02 07:37:50 +00:00
|
|
|
#include "txIXPathContext.h"
|
2005-11-02 07:41:38 +00:00
|
|
|
#include "txNodeSet.h"
|
2005-11-02 07:34:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This class represents a FunctionCall as defined by the XSL Working Draft
|
|
|
|
**/
|
|
|
|
|
|
|
|
//------------------/
|
|
|
|
//- Public Methods -/
|
|
|
|
//------------------/
|
|
|
|
|
2005-11-02 07:37:37 +00:00
|
|
|
/*
|
|
|
|
* Evaluates the given Expression and converts its result to a number.
|
|
|
|
*/
|
2009-11-15 10:57:49 +00:00
|
|
|
// static
|
|
|
|
nsresult
|
|
|
|
FunctionCall::evaluateToNumber(Expr* aExpr, txIEvalContext* aContext,
|
|
|
|
double* aResult)
|
2005-11-02 07:37:37 +00:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aExpr, "missing expression");
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<txAExprResult> exprResult;
|
2005-11-02 07:40:48 +00:00
|
|
|
nsresult rv = aExpr->evaluate(aContext, getter_AddRefs(exprResult));
|
2009-11-15 10:57:49 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
*aResult = exprResult->numberValue();
|
2005-11-02 07:37:37 +00:00
|
|
|
|
2009-11-15 10:57:49 +00:00
|
|
|
return NS_OK;
|
2005-11-02 07:37:37 +00:00
|
|
|
}
|
|
|
|
|
2005-11-02 07:37:19 +00:00
|
|
|
/*
|
|
|
|
* Evaluates the given Expression and converts its result to a NodeSet.
|
2013-04-03 01:14:24 +00:00
|
|
|
* If the result is not a NodeSet nullptr is returned.
|
2005-11-02 07:37:19 +00:00
|
|
|
*/
|
2005-11-02 07:40:48 +00:00
|
|
|
nsresult
|
|
|
|
FunctionCall::evaluateToNodeSet(Expr* aExpr, txIEvalContext* aContext,
|
2005-11-02 07:41:38 +00:00
|
|
|
txNodeSet** aResult)
|
2005-11-02 07:37:19 +00:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aExpr, "Missing expression to evaluate");
|
2012-07-30 14:20:58 +00:00
|
|
|
*aResult = nullptr;
|
2005-11-02 07:40:48 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<txAExprResult> exprRes;
|
2005-11-02 07:40:48 +00:00
|
|
|
nsresult rv = aExpr->evaluate(aContext, getter_AddRefs(exprRes));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2005-11-02 07:37:19 +00:00
|
|
|
|
2005-11-02 07:40:48 +00:00
|
|
|
if (exprRes->getResultType() != txAExprResult::NODESET) {
|
2005-11-02 07:40:09 +00:00
|
|
|
aContext->receiveError(NS_LITERAL_STRING("NodeSet expected as argument"), NS_ERROR_XSLT_NODESET_EXPECTED);
|
2005-11-02 07:40:48 +00:00
|
|
|
return NS_ERROR_XSLT_NODESET_EXPECTED;
|
2005-11-02 07:37:19 +00:00
|
|
|
}
|
|
|
|
|
2005-11-02 07:40:48 +00:00
|
|
|
*aResult =
|
2007-07-08 07:08:04 +00:00
|
|
|
static_cast<txNodeSet*>(static_cast<txAExprResult*>(exprRes));
|
2005-11-02 07:40:48 +00:00
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
|
|
|
|
return NS_OK;
|
2005-11-02 07:37:19 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
bool FunctionCall::requireParams(int32_t aParamCountMin,
|
|
|
|
int32_t aParamCountMax,
|
2005-11-02 07:37:50 +00:00
|
|
|
txIEvalContext* aContext)
|
2005-11-02 07:34:13 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t argc = mParams.Length();
|
2005-11-02 07:40:11 +00:00
|
|
|
if (argc < aParamCountMin ||
|
|
|
|
(aParamCountMax > -1 && argc > aParamCountMax)) {
|
2005-11-02 07:42:10 +00:00
|
|
|
nsAutoString err(NS_LITERAL_STRING("invalid number of parameters for function"));
|
|
|
|
#ifdef TX_TO_STRING
|
2005-11-02 07:42:33 +00:00
|
|
|
err.AppendLiteral(": ");
|
2005-11-02 07:34:13 +00:00
|
|
|
toString(err);
|
2005-11-02 07:42:10 +00:00
|
|
|
#endif
|
2005-11-02 07:37:50 +00:00
|
|
|
aContext->receiveError(err, NS_ERROR_XPATH_INVALID_ARG);
|
2005-11-02 07:34:13 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2005-11-02 07:34:13 +00:00
|
|
|
}
|
2005-11-02 07:40:11 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2005-11-02 07:40:11 +00:00
|
|
|
}
|
2005-11-02 07:34:13 +00:00
|
|
|
|
2006-01-26 01:50:30 +00:00
|
|
|
Expr*
|
2012-08-22 15:56:38 +00:00
|
|
|
FunctionCall::getSubExprAt(uint32_t aPos)
|
2006-01-26 01:50:30 +00:00
|
|
|
{
|
2006-12-12 21:20:15 +00:00
|
|
|
return mParams.SafeElementAt(aPos);
|
2006-01-26 01:50:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
FunctionCall::setSubExprAt(uint32_t aPos, Expr* aExpr)
|
2006-01-26 01:50:30 +00:00
|
|
|
{
|
2006-12-12 21:20:15 +00:00
|
|
|
NS_ASSERTION(aPos < mParams.Length(),
|
2006-01-26 01:50:30 +00:00
|
|
|
"setting bad subexpression index");
|
2006-12-12 21:20:15 +00:00
|
|
|
mParams[aPos] = aExpr;
|
2006-01-26 01:50:30 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2006-01-26 01:50:30 +00:00
|
|
|
FunctionCall::argsSensitiveTo(ContextSensitivity aContext)
|
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t i, len = mParams.Length();
|
2006-12-12 21:20:15 +00:00
|
|
|
for (i = 0; i < len; ++i) {
|
|
|
|
if (mParams[i]->isSensitiveTo(aContext)) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2006-01-26 01:50:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2006-01-26 01:50:30 +00:00
|
|
|
}
|
|
|
|
|
2005-11-02 07:42:10 +00:00
|
|
|
#ifdef TX_TO_STRING
|
|
|
|
void
|
|
|
|
FunctionCall::toString(nsAString& aDest)
|
2005-11-02 07:36:37 +00:00
|
|
|
{
|
2018-03-22 21:05:29 +00:00
|
|
|
appendName(aDest);
|
|
|
|
aDest.AppendLiteral("(");
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < mParams.Length(); ++i) {
|
2006-12-12 21:20:15 +00:00
|
|
|
if (i != 0) {
|
2014-01-04 15:02:17 +00:00
|
|
|
aDest.Append(char16_t(','));
|
Landing TX_BRIDGE_1_1_BRANCH.
Rewrite pretty much all variable and parameter handling. Makes global and local variables be handled differently. Global variables are no longer part of the variables stack, and are lazily evaluated. Fixes bugs 117658, 92929 and some unfiled bugs and fixes remaining parts of bugs 83651 and 96802. Patch by sicking, r=Pike sr=bz.
Fix for bug 156464: fix rounding problems in module, allow patterns without any '0's in the integer part and fix problems with grouping for standalone. Patch by sicking, r=Pike sr=bz.
Fix for bug 157340 (Probable bugs in extensions/transformiix/source/base/txMozillaString.h). Patch by peterv, r=Pike, sr=bz.
Fix for bug 146967 (Clean up Transformiix strings). Patch by peterv, r=sicking, sr=jst.
Fix for bug 156464 (Remove static strings from Transformiix). Patch by peterv, r=Pike, sr=jst.
2005-11-02 07:38:17 +00:00
|
|
|
}
|
2006-12-12 21:20:15 +00:00
|
|
|
mParams[i]->toString(aDest);
|
2005-11-02 07:34:13 +00:00
|
|
|
}
|
2014-01-04 15:02:17 +00:00
|
|
|
aDest.Append(char16_t(')'));
|
Landing TX_BRIDGE_1_1_BRANCH.
Rewrite pretty much all variable and parameter handling. Makes global and local variables be handled differently. Global variables are no longer part of the variables stack, and are lazily evaluated. Fixes bugs 117658, 92929 and some unfiled bugs and fixes remaining parts of bugs 83651 and 96802. Patch by sicking, r=Pike sr=bz.
Fix for bug 156464: fix rounding problems in module, allow patterns without any '0's in the integer part and fix problems with grouping for standalone. Patch by sicking, r=Pike sr=bz.
Fix for bug 157340 (Probable bugs in extensions/transformiix/source/base/txMozillaString.h). Patch by peterv, r=Pike, sr=bz.
Fix for bug 146967 (Clean up Transformiix strings). Patch by peterv, r=sicking, sr=jst.
Fix for bug 156464 (Remove static strings from Transformiix). Patch by peterv, r=Pike, sr=jst.
2005-11-02 07:38:17 +00:00
|
|
|
}
|
2005-11-02 07:42:10 +00:00
|
|
|
#endif
|