Changed scope resolution to use the new value_t.

This commit is contained in:
John Wiegley 2007-05-16 05:37:46 +00:00
parent 023f28630f
commit 8a2b87e6e1
6 changed files with 37 additions and 53 deletions

View file

@ -82,27 +82,24 @@ value_t report_t::ftime(xml::xpath_t::scope_t * locals)
#endif #endif
} }
bool report_t::resolve(const string& name, value_t& result, optional<value_t>
xml::xpath_t::scope_t * locals) report_t::resolve(const string& name, xml::xpath_t::scope_t * locals)
{ {
const char * p = name.c_str(); const char * p = name.c_str();
switch (*p) { switch (*p) {
case 'a': case 'a':
if (name == "abbrev") { if (name == "abbrev") {
result = abbrev(locals); return abbrev(locals);
return true;
} }
break; break;
case 'f': case 'f':
if (name == "ftime") { if (name == "ftime") {
result = ftime(locals); return ftime(locals);
return true;
} }
break; break;
} }
return xml::xpath_t::scope_t::resolve(name, locals);
return xml::xpath_t::scope_t::resolve(name, result, locals);
} }
xml::xpath_t::ptr_op_t report_t::lookup(const string& name) xml::xpath_t::ptr_op_t report_t::lookup(const string& name)

View file

@ -161,7 +161,7 @@ class report_t : public xml::xpath_t::scope_t
// Scope members // Scope members
// //
virtual bool resolve(const string& name, value_t& result, virtual optional<value_t> resolve(const string& name,
xml::xpath_t::scope_t * locals); xml::xpath_t::scope_t * locals);
virtual xml::xpath_t::ptr_op_t lookup(const string& name); virtual xml::xpath_t::ptr_op_t lookup(const string& name);
}; };

View file

@ -173,41 +173,35 @@ std::size_t session_t::read_data(xml::builder_t& builder,
return entry_count; return entry_count;
} }
bool session_t::resolve(const string& name, value_t& result, optional<value_t>
xml::xpath_t::scope_t * locals) session_t::resolve(const string& name, xml::xpath_t::scope_t * locals)
{ {
const char * p = name.c_str(); const char * p = name.c_str();
switch (*p) { switch (*p) {
case 'd': case 'd':
#if 0
if (name == "date_format") { if (name == "date_format") {
// jww (2007-04-18): What to do here? // jww (2007-04-18): What to do here?
#if 0 return value_t(moment_t::output_format, true);
result.set_string(moment_t::output_format);
#endif
return true;
} }
#endif
break; break;
case 'n': case 'n':
switch (*++p) { switch (*++p) {
case 'o': case 'o':
if (name == "now") { if (name == "now")
result = now; return value_t(now);
return true;
}
break; break;
} }
break; break;
case 'r': case 'r':
if (name == "register_format") { if (name == "register_format")
result = register_format; return value_t(register_format, true);
return true;
}
break; break;
} }
return xml::xpath_t::scope_t::resolve(name, locals);
return xml::xpath_t::scope_t::resolve(name, result, locals);
} }
xml::xpath_t::ptr_op_t session_t::lookup(const string& name) xml::xpath_t::ptr_op_t session_t::lookup(const string& name)

View file

@ -180,7 +180,7 @@ class session_t : public xml::xpath_t::scope_t
// Scope members // Scope members
// //
virtual bool resolve(const string& name, value_t& result, virtual optional<value_t> resolve(const string& name,
xml::xpath_t::scope_t * locals = NULL); xml::xpath_t::scope_t * locals = NULL);
virtual xml::xpath_t::ptr_op_t lookup(const string& name); virtual xml::xpath_t::ptr_op_t lookup(const string& name);

View file

@ -483,33 +483,29 @@ void xpath_t::scope_t::define(const string& name, const function_t& def) {
define(name, wrap_functor(def)); define(name, wrap_functor(def));
} }
bool xpath_t::function_scope_t::resolve(const string& name, optional<value_t>
value_t& result, xpath_t::function_scope_t::resolve(const string& name, scope_t * locals)
scope_t * locals)
{ {
switch (name[0]) { switch (name[0]) {
case 'l': case 'l':
if (name == "last") { if (name == "last") {
result = (long)size; return value_t((long)size);
return true;
} }
break; break;
case 'p': case 'p':
if (name == "position") { if (name == "position") {
result = (long)index + 1; return value_t((long)index + 1);
return true;
} }
break; break;
case 't': case 't':
if (name == "text") { if (name == "text") {
result = node.to_value(); return node.to_value();
return true;
} }
break; break;
} }
return scope_t::resolve(name, result, locals); return scope_t::resolve(name, locals);
} }
xpath_t::ptr_op_t 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: case FUNC_NAME:
if (scope) { if (scope) {
if (resolve) { if (resolve) {
value_t temp; if (optional<value_t> temp = scope->resolve(as_string()))
if (scope->resolve(as_string(), temp)) return wrap_value(*temp);
return wrap_value(temp);
} }
if (ptr_op_t def = scope->lookup(as_string())) if (ptr_op_t def = scope->lookup(as_string()))
return def->compile(context, scope, resolve); 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; call_args->args = call_seq;
if (left()->kind == FUNC_NAME) { if (left()->kind == FUNC_NAME) {
if (resolve) { if (resolve && scope)
value_t temp; if (optional<value_t> temp =
if (scope && scope->resolve(left()->as_string(), temp, call_args.get())) scope->resolve(left()->as_string(), call_args.get()))
return wrap_value(temp); return wrap_value(*temp);
}
// Don't compile to the left, otherwise the function name may // Don't compile to the left, otherwise the function name may
// get resolved before we have a chance to call it // get resolved before we have a chance to call it

View file

@ -84,12 +84,11 @@ public:
public: public:
virtual void define(const string& name, ptr_op_t def); virtual void define(const string& name, ptr_op_t def);
// jww (2007-05-15): ?? virtual optional<value_t> resolve(const string& name,
virtual bool resolve(const string& name, value_t& result,
scope_t * locals = NULL) { scope_t * locals = NULL) {
if (parent) if (parent)
return parent->resolve(name, result, locals); return parent->resolve(name, locals);
return false; return none;
} }
virtual ptr_op_t lookup(const string& name); virtual ptr_op_t lookup(const string& name);
@ -116,7 +115,7 @@ public:
: scope_t(_parent, STATIC), node(_node), index(_index), : scope_t(_parent, STATIC), node(_node), index(_index),
size(_size) {} size(_size) {}
virtual bool resolve(const string& name, value_t& result, virtual optional<value_t> resolve(const string& name,
scope_t * locals = NULL); scope_t * locals = NULL);
}; };