2013-04-09 08:28:16 +04:00
|
|
|
#include "evalcontext.h"
|
|
|
|
#include "module.h"
|
|
|
|
#include "expression.h"
|
|
|
|
#include "function.h"
|
|
|
|
#include "printutils.h"
|
|
|
|
#include "builtin.h"
|
2013-04-20 01:52:01 +04:00
|
|
|
#include "localscope.h"
|
2014-11-25 01:30:05 +03:00
|
|
|
#include "exceptions.h"
|
2013-04-09 08:28:16 +04:00
|
|
|
|
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
|
2014-11-17 08:57:36 +03:00
|
|
|
EvalContext::EvalContext(const Context *parent,
|
|
|
|
const AssignmentList &args, const class LocalScope *const scope)
|
|
|
|
: Context(parent), eval_arguments(args), scope(scope)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-04-19 05:42:33 +04:00
|
|
|
const std::string &EvalContext::getArgName(size_t i) const
|
|
|
|
{
|
|
|
|
assert(i < this->eval_arguments.size());
|
|
|
|
return this->eval_arguments[i].first;
|
|
|
|
}
|
|
|
|
|
2014-11-23 08:59:17 +03:00
|
|
|
ValuePtr EvalContext::getArgValue(size_t i, const Context *ctx) const
|
2013-04-19 05:42:33 +04:00
|
|
|
{
|
|
|
|
assert(i < this->eval_arguments.size());
|
|
|
|
const Assignment &arg = this->eval_arguments[i];
|
2014-11-24 20:54:14 +03:00
|
|
|
ValuePtr v;
|
|
|
|
if (arg.second) {
|
2014-12-04 21:40:15 +03:00
|
|
|
v = arg.second->evaluate(ctx ? ctx : this);
|
2014-11-24 20:54:14 +03:00
|
|
|
}
|
|
|
|
return v;
|
2013-04-19 05:42:33 +04:00
|
|
|
}
|
|
|
|
|
2013-04-20 01:52:01 +04:00
|
|
|
size_t EvalContext::numChildren() const
|
|
|
|
{
|
|
|
|
return this->scope ? this->scope->children.size() : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ModuleInstantiation *EvalContext::getChild(size_t i) const
|
|
|
|
{
|
|
|
|
return this->scope ? this->scope->children[i] : NULL;
|
|
|
|
}
|
|
|
|
|
2013-04-09 08:28:16 +04:00
|
|
|
#ifdef DEBUG
|
2014-04-05 08:40:23 +04:00
|
|
|
std::string EvalContext::dump(const AbstractModule *mod, const ModuleInstantiation *inst)
|
2013-04-09 08:28:16 +04:00
|
|
|
{
|
2014-04-05 08:40:23 +04:00
|
|
|
std::stringstream s;
|
|
|
|
if (inst)
|
|
|
|
s << boost::format("EvalContext %p (%p) for %s inst (%p)") % this % this->parent % inst->name() % inst;
|
|
|
|
else
|
|
|
|
s << boost::format("Context: %p (%p)") % this % this->parent;
|
|
|
|
s << boost::format(" document path: %s") % this->document_path;
|
2013-04-09 08:28:16 +04:00
|
|
|
|
2014-04-05 08:40:23 +04:00
|
|
|
s << boost::format(" eval args:");
|
2014-01-19 03:26:04 +04:00
|
|
|
for (size_t i=0;i<this->eval_arguments.size();i++) {
|
2014-04-05 08:40:23 +04:00
|
|
|
s << boost::format(" %s = %s") % this->eval_arguments[i].first % this->eval_arguments[i].second;
|
2013-04-09 08:28:16 +04:00
|
|
|
}
|
2013-04-20 01:52:01 +04:00
|
|
|
if (this->scope && this->scope->children.size() > 0) {
|
2014-04-05 08:40:23 +04:00
|
|
|
s << boost::format(" children:");
|
2013-04-20 01:52:01 +04:00
|
|
|
BOOST_FOREACH(const ModuleInstantiation *ch, this->scope->children) {
|
2014-04-05 08:40:23 +04:00
|
|
|
s << boost::format(" %s") % ch->name();
|
2013-04-09 08:28:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mod) {
|
|
|
|
const Module *m = dynamic_cast<const Module*>(mod);
|
|
|
|
if (m) {
|
2014-04-05 08:40:23 +04:00
|
|
|
s << boost::format(" module args:");
|
2013-04-19 02:34:14 +04:00
|
|
|
BOOST_FOREACH(const Assignment &arg, m->definition_arguments) {
|
2014-11-23 08:59:17 +03:00
|
|
|
s << boost::format(" %s = %s") % arg.first % *(variables[arg.first]);
|
2013-04-09 08:28:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-04-05 08:40:23 +04:00
|
|
|
return s.str();
|
2013-04-09 08:28:16 +04:00
|
|
|
}
|
|
|
|
#endif
|
2014-04-05 08:40:23 +04:00
|
|
|
|