summaryrefslogtreecommitdiff
path: root/src/module.cc
diff options
context:
space:
mode:
authorŁukasz Stelmach <stlman@poczta.fm>2013-08-15 09:25:55 (GMT)
committerŁukasz Stelmach <stlman@poczta.fm>2013-08-17 14:22:00 (GMT)
commitd67e0129161a98f852ed2685f43e7eb7c7538bf0 (patch)
tree418dd6a58f70528d0d77b5d19f03161d95dfc00c /src/module.cc
parentaf7e8320e2d0fda0e2b8505f50080ff3d33e7531 (diff)
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]
Diffstat (limited to 'src/module.cc')
-rw-r--r--src/module.cc7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/module.cc b/src/module.cc
index 8fb8506..970dd56 100644
--- a/src/module.cc
+++ b/src/module.cc
@@ -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;
}
contact: Jan Huwald // Impressum