It was somewhat poorly thought out since it's unable to gather nodes of
a base class type.
{
module->source_map.merge_from(mod.source_map);
- vector<Import *> imports = NodeGatherer<Import>().apply(mod.shared);
+ vector<Import *> imports;
+ for(NodeList<Statement>::const_iterator i=mod.shared.content.body.begin(); i!=mod.shared.content.body.end(); ++i)
+ if(Import *imp = dynamic_cast<Import *>(i->get()))
+ imports.push_back(imp);
for(vector<Import *>::iterator i=imports.begin(); i!=imports.end(); ++i)
import(res, (*i)->module);
NodeRemover().apply(mod.shared, set<Node *>(imports.begin(), imports.end()));
virtual void visit(Return &);
};
-/** Gathers nodes of a particular type from the syntax tree. */
-template<typename T>
-class NodeGatherer: private TraversingVisitor
-{
-private:
- std::vector<T *> nodes;
-
-public:
- const std::vector<T *> &apply(Stage &s) { s.content.visit(*this); return nodes; }
-
-private:
- virtual void visit(T &n) { nodes.push_back(&n); }
-};
-
/** Removes a set of nodes from the syntax tree. */
class NodeRemover: private TraversingVisitor
{