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 "nsIAtom.h"
|
|
|
|
#include "txNodeSet.h"
|
2011-09-19 13:07:17 -07:00
|
|
|
#include "nsGkAtoms.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "txIXPathContext.h"
|
|
|
|
|
|
|
|
//-------------------/
|
|
|
|
//- VariableRefExpr -/
|
|
|
|
//-------------------/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a VariableRefExpr with the given variable name
|
|
|
|
**/
|
|
|
|
VariableRefExpr::VariableRefExpr(nsIAtom* aPrefix, nsIAtom* aLocalName,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aNSID)
|
2007-03-22 10:30:00 -07:00
|
|
|
: mPrefix(aPrefix), mLocalName(aLocalName), mNamespace(aNSID)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mLocalName, "VariableRefExpr without local name?");
|
2011-09-19 13:07:17 -07:00
|
|
|
if (mPrefix == nsGkAtoms::_empty)
|
2007-03-22 10:30:00 -07:00
|
|
|
mPrefix = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
VariableRefExpr::evaluate(txIEvalContext* aContext, txAExprResult** aResult)
|
|
|
|
{
|
|
|
|
nsresult rv = aContext->getVariable(mNamespace, mLocalName, *aResult);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// XXX report error, undefined variable
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
TX_IMPL_EXPR_STUBS_0(VariableRefExpr, ANY_RESULT)
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
VariableRefExpr::isSensitiveTo(ContextSensitivity aContext)
|
|
|
|
{
|
|
|
|
return !!(aContext & VARIABLES_CONTEXT);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef TX_TO_STRING
|
|
|
|
void
|
|
|
|
VariableRefExpr::toString(nsAString& aDest)
|
|
|
|
{
|
2014-01-04 07:02:17 -08:00
|
|
|
aDest.Append(char16_t('$'));
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mPrefix) {
|
|
|
|
nsAutoString prefix;
|
|
|
|
mPrefix->ToString(prefix);
|
|
|
|
aDest.Append(prefix);
|
2014-01-04 07:02:17 -08:00
|
|
|
aDest.Append(char16_t(':'));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
nsAutoString lname;
|
|
|
|
mLocalName->ToString(lname);
|
|
|
|
aDest.Append(lname);
|
|
|
|
}
|
|
|
|
#endif
|