Introduce '_current_module' and '_parent_module' variables

Add two built-in variables that provide access to the names
of the current and the previously instantiated modules.

Having these variables simplifies generation of BOMs and assembly
graphs (e.g. with GraphViz).

[std::stack]
brodykenrick-master
Łukasz Stelmach 2013-08-15 11:25:55 +02:00
parent af7e8320e2
commit d67e012916
2 changed files with 10 additions and 0 deletions

View File

@ -153,6 +153,8 @@ std::vector<AbstractNode*> IfElseModuleInstantiation::instantiateElseChildren(co
return this->else_scope.instantiateChildren(evalctx);
}
std::stack<std::string> Module::stack;
Module::~Module()
{
}
@ -181,15 +183,20 @@ AbstractNode *Module::instantiate(const Context *ctx, const ModuleInstantiation
ModuleContext c(ctx, evalctx);
c.initializeModule(*this);
c.set_variable("_current_module", inst->name());
if (!stack.empty())
c.set_variable("_parent_module", stack.top());
c.set_variable("$children", Value(double(inst->scope.children.size())));
// FIXME: Set document path to the path of the module
#if 0 && DEBUG
c.dump(this, inst);
#endif
stack.push(inst->name());
AbstractNode *node = new AbstractNode(inst);
std::vector<AbstractNode *> instantiatednodes = this->scope.instantiateChildren(&c);
node->children.insert(node->children.end(), instantiatednodes.begin(), instantiatednodes.end());
stack.pop();
return node;
}

View File

@ -4,6 +4,7 @@
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <boost/unordered_map.hpp>
#include <boost/unordered_set.hpp>
#include <time.h>
@ -77,6 +78,8 @@ public:
AssignmentList definition_arguments;
LocalScope scope;
private:
static std::stack<std::string> stack;
};
// FIXME: A FileModule doesn't have definition arguments, so we shouldn't really