Changed scope resolution to use the new value_t.
This commit is contained in:
parent
023f28630f
commit
8a2b87e6e1
6 changed files with 37 additions and 53 deletions
|
|
@ -82,27 +82,24 @@ value_t report_t::ftime(xml::xpath_t::scope_t * locals)
|
|||
#endif
|
||||
}
|
||||
|
||||
bool report_t::resolve(const string& name, value_t& result,
|
||||
xml::xpath_t::scope_t * locals)
|
||||
optional<value_t>
|
||||
report_t::resolve(const string& name, xml::xpath_t::scope_t * locals)
|
||||
{
|
||||
const char * p = name.c_str();
|
||||
switch (*p) {
|
||||
case 'a':
|
||||
if (name == "abbrev") {
|
||||
result = abbrev(locals);
|
||||
return true;
|
||||
return abbrev(locals);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
if (name == "ftime") {
|
||||
result = ftime(locals);
|
||||
return true;
|
||||
return ftime(locals);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return xml::xpath_t::scope_t::resolve(name, result, locals);
|
||||
return xml::xpath_t::scope_t::resolve(name, locals);
|
||||
}
|
||||
|
||||
xml::xpath_t::ptr_op_t report_t::lookup(const string& name)
|
||||
|
|
|
|||
|
|
@ -161,8 +161,8 @@ class report_t : public xml::xpath_t::scope_t
|
|||
// Scope members
|
||||
//
|
||||
|
||||
virtual bool resolve(const string& name, value_t& result,
|
||||
xml::xpath_t::scope_t * locals);
|
||||
virtual optional<value_t> resolve(const string& name,
|
||||
xml::xpath_t::scope_t * locals);
|
||||
virtual xml::xpath_t::ptr_op_t lookup(const string& name);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -173,41 +173,35 @@ std::size_t session_t::read_data(xml::builder_t& builder,
|
|||
return entry_count;
|
||||
}
|
||||
|
||||
bool session_t::resolve(const string& name, value_t& result,
|
||||
xml::xpath_t::scope_t * locals)
|
||||
optional<value_t>
|
||||
session_t::resolve(const string& name, xml::xpath_t::scope_t * locals)
|
||||
{
|
||||
const char * p = name.c_str();
|
||||
switch (*p) {
|
||||
case 'd':
|
||||
#if 0
|
||||
if (name == "date_format") {
|
||||
// jww (2007-04-18): What to do here?
|
||||
#if 0
|
||||
result.set_string(moment_t::output_format);
|
||||
#endif
|
||||
return true;
|
||||
return value_t(moment_t::output_format, true);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
switch (*++p) {
|
||||
case 'o':
|
||||
if (name == "now") {
|
||||
result = now;
|
||||
return true;
|
||||
}
|
||||
if (name == "now")
|
||||
return value_t(now);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
if (name == "register_format") {
|
||||
result = register_format;
|
||||
return true;
|
||||
}
|
||||
if (name == "register_format")
|
||||
return value_t(register_format, true);
|
||||
break;
|
||||
}
|
||||
|
||||
return xml::xpath_t::scope_t::resolve(name, result, locals);
|
||||
return xml::xpath_t::scope_t::resolve(name, locals);
|
||||
}
|
||||
|
||||
xml::xpath_t::ptr_op_t session_t::lookup(const string& name)
|
||||
|
|
|
|||
|
|
@ -180,8 +180,8 @@ class session_t : public xml::xpath_t::scope_t
|
|||
// Scope members
|
||||
//
|
||||
|
||||
virtual bool resolve(const string& name, value_t& result,
|
||||
xml::xpath_t::scope_t * locals = NULL);
|
||||
virtual optional<value_t> resolve(const string& name,
|
||||
xml::xpath_t::scope_t * locals = NULL);
|
||||
virtual xml::xpath_t::ptr_op_t lookup(const string& name);
|
||||
|
||||
//
|
||||
|
|
|
|||
30
src/xpath.cc
30
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
|
||||
|
|
|
|||
13
src/xpath.h
13
src/xpath.h
|
|
@ -84,12 +84,11 @@ public:
|
|||
|
||||
public:
|
||||
virtual void define(const string& name, ptr_op_t def);
|
||||
// jww (2007-05-15): ??
|
||||
virtual bool resolve(const string& name, value_t& result,
|
||||
scope_t * locals = NULL) {
|
||||
virtual optional<value_t> resolve(const string& name,
|
||||
scope_t * locals = NULL) {
|
||||
if (parent)
|
||||
return parent->resolve(name, result, locals);
|
||||
return false;
|
||||
return parent->resolve(name, locals);
|
||||
return none;
|
||||
}
|
||||
virtual ptr_op_t lookup(const string& name);
|
||||
|
||||
|
|
@ -116,8 +115,8 @@ public:
|
|||
: scope_t(_parent, STATIC), node(_node), index(_index),
|
||||
size(_size) {}
|
||||
|
||||
virtual bool resolve(const string& name, value_t& result,
|
||||
scope_t * locals = NULL);
|
||||
virtual optional<value_t> resolve(const string& name,
|
||||
scope_t * locals = NULL);
|
||||
};
|
||||
|
||||
#define XPATH_PARSE_NORMAL 0x00
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue