michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "txExpr.h" michael@0: #include "nsIAtom.h" michael@0: #include "txNodeSet.h" michael@0: #include "nsGkAtoms.h" michael@0: #include "txIXPathContext.h" michael@0: michael@0: //-------------------/ michael@0: //- VariableRefExpr -/ michael@0: //-------------------/ michael@0: michael@0: /** michael@0: * Creates a VariableRefExpr with the given variable name michael@0: **/ michael@0: VariableRefExpr::VariableRefExpr(nsIAtom* aPrefix, nsIAtom* aLocalName, michael@0: int32_t aNSID) michael@0: : mPrefix(aPrefix), mLocalName(aLocalName), mNamespace(aNSID) michael@0: { michael@0: NS_ASSERTION(mLocalName, "VariableRefExpr without local name?"); michael@0: if (mPrefix == nsGkAtoms::_empty) michael@0: mPrefix = 0; michael@0: } michael@0: michael@0: /** michael@0: * Evaluates this Expr based on the given context node and processor state michael@0: * @param context the context node for evaluation of this Expr michael@0: * @param ps the ContextState containing the stack information needed michael@0: * for evaluation michael@0: * @return the result of the evaluation michael@0: **/ michael@0: nsresult michael@0: VariableRefExpr::evaluate(txIEvalContext* aContext, txAExprResult** aResult) michael@0: { michael@0: nsresult rv = aContext->getVariable(mNamespace, mLocalName, *aResult); michael@0: if (NS_FAILED(rv)) { michael@0: // XXX report error, undefined variable michael@0: return rv; michael@0: } michael@0: return NS_OK; michael@0: } michael@0: michael@0: TX_IMPL_EXPR_STUBS_0(VariableRefExpr, ANY_RESULT) michael@0: michael@0: bool michael@0: VariableRefExpr::isSensitiveTo(ContextSensitivity aContext) michael@0: { michael@0: return !!(aContext & VARIABLES_CONTEXT); michael@0: } michael@0: michael@0: #ifdef TX_TO_STRING michael@0: void michael@0: VariableRefExpr::toString(nsAString& aDest) michael@0: { michael@0: aDest.Append(char16_t('$')); michael@0: if (mPrefix) { michael@0: nsAutoString prefix; michael@0: mPrefix->ToString(prefix); michael@0: aDest.Append(prefix); michael@0: aDest.Append(char16_t(':')); michael@0: } michael@0: nsAutoString lname; michael@0: mLocalName->ToString(lname); michael@0: aDest.Append(lname); michael@0: } michael@0: #endif