gecko-dev/dom/xslt/xpath/txFunctionCall.cpp

126 lines
3.2 KiB
C++
Raw Normal View History

/* -*- 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/. */
#include "txExpr.h"
#include "nsAtom.h"
#include "txIXPathContext.h"
#include "txNodeSet.h"
/**
* This class represents a FunctionCall as defined by the XSL Working Draft
**/
//------------------/
//- Public Methods -/
//------------------/
/*
* Evaluates the given Expression and converts its result to a number.
*/
// static
nsresult
FunctionCall::evaluateToNumber(Expr* aExpr, txIEvalContext* aContext,
double* aResult)
{
NS_ASSERTION(aExpr, "missing expression");
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 05:24:48 +00:00
RefPtr<txAExprResult> exprResult;
nsresult rv = aExpr->evaluate(aContext, getter_AddRefs(exprResult));
NS_ENSURE_SUCCESS(rv, rv);
*aResult = exprResult->numberValue();
return NS_OK;
}
/*
* Evaluates the given Expression and converts its result to a NodeSet.
* If the result is not a NodeSet nullptr is returned.
*/
nsresult
FunctionCall::evaluateToNodeSet(Expr* aExpr, txIEvalContext* aContext,
txNodeSet** aResult)
{
NS_ASSERTION(aExpr, "Missing expression to evaluate");
*aResult = nullptr;
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 05:24:48 +00:00
RefPtr<txAExprResult> exprRes;
nsresult rv = aExpr->evaluate(aContext, getter_AddRefs(exprRes));
NS_ENSURE_SUCCESS(rv, rv);
if (exprRes->getResultType() != txAExprResult::NODESET) {
aContext->receiveError(NS_LITERAL_STRING("NodeSet expected as argument"), NS_ERROR_XSLT_NODESET_EXPECTED);
return NS_ERROR_XSLT_NODESET_EXPECTED;
}
*aResult =
static_cast<txNodeSet*>(static_cast<txAExprResult*>(exprRes));
NS_ADDREF(*aResult);
return NS_OK;
}
bool FunctionCall::requireParams(int32_t aParamCountMin,
int32_t aParamCountMax,
txIEvalContext* aContext)
{
int32_t argc = mParams.Length();
if (argc < aParamCountMin ||
(aParamCountMax > -1 && argc > aParamCountMax)) {
nsAutoString err(NS_LITERAL_STRING("invalid number of parameters for function"));
#ifdef TX_TO_STRING
err.AppendLiteral(": ");
toString(err);
#endif
aContext->receiveError(err, NS_ERROR_XPATH_INVALID_ARG);
return false;
}
return true;
}
Expr*
FunctionCall::getSubExprAt(uint32_t aPos)
{
return mParams.SafeElementAt(aPos);
}
void
FunctionCall::setSubExprAt(uint32_t aPos, Expr* aExpr)
{
NS_ASSERTION(aPos < mParams.Length(),
"setting bad subexpression index");
mParams[aPos] = aExpr;
}
bool
FunctionCall::argsSensitiveTo(ContextSensitivity aContext)
{
uint32_t i, len = mParams.Length();
for (i = 0; i < len; ++i) {
if (mParams[i]->isSensitiveTo(aContext)) {
return true;
}
}
return false;
}
#ifdef TX_TO_STRING
void
FunctionCall::toString(nsAString& aDest)
{
appendName(aDest);
aDest.AppendLiteral("(");
for (uint32_t i = 0; i < mParams.Length(); ++i) {
if (i != 0) {
aDest.Append(char16_t(','));
}
mParams[i]->toString(aDest);
}
aDest.Append(char16_t(')'));
}
#endif