Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "txExpr.h"
7 : #include "nsIAtom.h"
8 : #include "txNodeSet.h"
9 : #include "nsGkAtoms.h"
10 : #include "txIXPathContext.h"
11 :
12 : //-------------------/
13 : //- VariableRefExpr -/
14 : //-------------------/
15 :
16 : /**
17 : * Creates a VariableRefExpr with the given variable name
18 : **/
19 0 : VariableRefExpr::VariableRefExpr(nsIAtom* aPrefix, nsIAtom* aLocalName,
20 0 : int32_t aNSID)
21 0 : : mPrefix(aPrefix), mLocalName(aLocalName), mNamespace(aNSID)
22 : {
23 0 : NS_ASSERTION(mLocalName, "VariableRefExpr without local name?");
24 0 : if (mPrefix == nsGkAtoms::_empty)
25 0 : mPrefix = nullptr;
26 0 : }
27 :
28 : /**
29 : * Evaluates this Expr based on the given context node and processor state
30 : * @param context the context node for evaluation of this Expr
31 : * @param ps the ContextState containing the stack information needed
32 : * for evaluation
33 : * @return the result of the evaluation
34 : **/
35 : nsresult
36 0 : VariableRefExpr::evaluate(txIEvalContext* aContext, txAExprResult** aResult)
37 : {
38 0 : nsresult rv = aContext->getVariable(mNamespace, mLocalName, *aResult);
39 0 : if (NS_FAILED(rv)) {
40 : // XXX report error, undefined variable
41 0 : return rv;
42 : }
43 0 : return NS_OK;
44 : }
45 :
46 0 : TX_IMPL_EXPR_STUBS_0(VariableRefExpr, ANY_RESULT)
47 :
48 : bool
49 0 : VariableRefExpr::isSensitiveTo(ContextSensitivity aContext)
50 : {
51 0 : return !!(aContext & VARIABLES_CONTEXT);
52 : }
53 :
54 : #ifdef TX_TO_STRING
55 : void
56 0 : VariableRefExpr::toString(nsAString& aDest)
57 : {
58 0 : aDest.Append(char16_t('$'));
59 0 : if (mPrefix) {
60 0 : nsAutoString prefix;
61 0 : mPrefix->ToString(prefix);
62 0 : aDest.Append(prefix);
63 0 : aDest.Append(char16_t(':'));
64 : }
65 0 : nsAutoString lname;
66 0 : mLocalName->ToString(lname);
67 0 : aDest.Append(lname);
68 0 : }
69 : #endif
|