diff options
author | John Wiegley <johnw@newartisans.com> | 2007-05-16 05:37:46 +0000 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2008-04-13 03:38:52 -0400 |
commit | 8a2b87e6e1f5cd8784130f3cfcd1911b214c55cc (patch) | |
tree | b34a2bee1fa2772050ace252a4c691ffcf927c68 /src/xpath.cc | |
parent | 023f28630f7ed8f845eab00b137d58cc79b4445b (diff) | |
download | ledger-8a2b87e6e1f5cd8784130f3cfcd1911b214c55cc.tar.gz ledger-8a2b87e6e1f5cd8784130f3cfcd1911b214c55cc.tar.bz2 ledger-8a2b87e6e1f5cd8784130f3cfcd1911b214c55cc.zip |
Changed scope resolution to use the new value_t.
Diffstat (limited to 'src/xpath.cc')
-rw-r--r-- | src/xpath.cc | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/src/xpath.cc b/src/xpath.cc index 80749d72..2a28956d 100644 --- a/src/xpath.cc +++ b/src/xpath.cc @@ -483,33 +483,29 @@ void xpath_t::scope_t::define(const string& name, const function_t& def) { define(name, wrap_functor(def)); } -bool xpath_t::function_scope_t::resolve(const string& name, - value_t& result, - scope_t * locals) +optional<value_t> +xpath_t::function_scope_t::resolve(const string& name, scope_t * locals) { switch (name[0]) { case 'l': if (name == "last") { - result = (long)size; - return true; + return value_t((long)size); } break; case 'p': if (name == "position") { - result = (long)index + 1; - return true; + return value_t((long)index + 1); } break; case 't': if (name == "text") { - result = node.to_value(); - return true; + return node.to_value(); } break; } - return scope_t::resolve(name, result, locals); + return scope_t::resolve(name, locals); } xpath_t::ptr_op_t @@ -1208,9 +1204,8 @@ xpath_t::op_t::compile(const node_t& context, scope_t * scope, bool resolve) case FUNC_NAME: if (scope) { if (resolve) { - value_t temp; - if (scope->resolve(as_string(), temp)) - return wrap_value(temp); + if (optional<value_t> temp = scope->resolve(as_string())) + return wrap_value(*temp); } if (ptr_op_t def = scope->lookup(as_string())) return def->compile(context, scope, resolve); @@ -1543,11 +1538,10 @@ xpath_t::op_t::compile(const node_t& context, scope_t * scope, bool resolve) call_args->args = call_seq; if (left()->kind == FUNC_NAME) { - if (resolve) { - value_t temp; - if (scope && scope->resolve(left()->as_string(), temp, call_args.get())) - return wrap_value(temp); - } + if (resolve && scope) + if (optional<value_t> temp = + scope->resolve(left()->as_string(), call_args.get())) + return wrap_value(*temp); // Don't compile to the left, otherwise the function name may // get resolved before we have a chance to call it |