txVariableRefExpr.cpp (1913B)
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #include "nsAtom.h" 7 #include "nsGkAtoms.h" 8 #include "txExpr.h" 9 #include "txIXPathContext.h" 10 #include "txNodeSet.h" 11 12 //-------------------/ 13 //- VariableRefExpr -/ 14 //-------------------/ 15 16 /** 17 * Creates a VariableRefExpr with the given variable name 18 **/ 19 VariableRefExpr::VariableRefExpr(nsAtom* aPrefix, nsAtom* aLocalName, 20 int32_t aNSID) 21 : mPrefix(aPrefix), mLocalName(aLocalName), mNamespace(aNSID) { 22 NS_ASSERTION(mLocalName, "VariableRefExpr without local name?"); 23 if (mPrefix == nsGkAtoms::_empty) mPrefix = nullptr; 24 } 25 26 /** 27 * Evaluates this Expr based on the given context node and processor state 28 * @param context the context node for evaluation of this Expr 29 * @param ps the ContextState containing the stack information needed 30 * for evaluation 31 * @return the result of the evaluation 32 **/ 33 nsresult VariableRefExpr::evaluate(txIEvalContext* aContext, 34 txAExprResult** aResult) { 35 nsresult rv = aContext->getVariable(mNamespace, mLocalName, *aResult); 36 if (NS_FAILED(rv)) { 37 // XXX report error, undefined variable 38 return rv; 39 } 40 return NS_OK; 41 } 42 43 TX_IMPL_EXPR_STUBS_0(VariableRefExpr, ANY_RESULT) 44 45 bool VariableRefExpr::isSensitiveTo(ContextSensitivity aContext) { 46 return !!(aContext & VARIABLES_CONTEXT); 47 } 48 49 #ifdef TX_TO_STRING 50 void VariableRefExpr::toString(nsAString& aDest) { 51 aDest.Append(char16_t('$')); 52 if (mPrefix) { 53 nsAutoString prefix; 54 mPrefix->ToString(prefix); 55 aDest.Append(prefix); 56 aDest.Append(char16_t(':')); 57 } 58 nsAutoString lname; 59 mLocalName->ToString(lname); 60 aDest.Append(lname); 61 } 62 #endif