|
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 VariableRefExpr::VariableRefExpr(nsIAtom* aPrefix, nsIAtom* aLocalName, |
|
20 int32_t aNSID) |
|
21 : mPrefix(aPrefix), mLocalName(aLocalName), mNamespace(aNSID) |
|
22 { |
|
23 NS_ASSERTION(mLocalName, "VariableRefExpr without local name?"); |
|
24 if (mPrefix == nsGkAtoms::_empty) |
|
25 mPrefix = 0; |
|
26 } |
|
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 VariableRefExpr::evaluate(txIEvalContext* aContext, txAExprResult** aResult) |
|
37 { |
|
38 nsresult rv = aContext->getVariable(mNamespace, mLocalName, *aResult); |
|
39 if (NS_FAILED(rv)) { |
|
40 // XXX report error, undefined variable |
|
41 return rv; |
|
42 } |
|
43 return NS_OK; |
|
44 } |
|
45 |
|
46 TX_IMPL_EXPR_STUBS_0(VariableRefExpr, ANY_RESULT) |
|
47 |
|
48 bool |
|
49 VariableRefExpr::isSensitiveTo(ContextSensitivity aContext) |
|
50 { |
|
51 return !!(aContext & VARIABLES_CONTEXT); |
|
52 } |
|
53 |
|
54 #ifdef TX_TO_STRING |
|
55 void |
|
56 VariableRefExpr::toString(nsAString& aDest) |
|
57 { |
|
58 aDest.Append(char16_t('$')); |
|
59 if (mPrefix) { |
|
60 nsAutoString prefix; |
|
61 mPrefix->ToString(prefix); |
|
62 aDest.Append(prefix); |
|
63 aDest.Append(char16_t(':')); |
|
64 } |
|
65 nsAutoString lname; |
|
66 mLocalName->ToString(lname); |
|
67 aDest.Append(lname); |
|
68 } |
|
69 #endif |