This article (http://ift.tt/1A6QziX) introduces a very interesting concept of how to use inline visitors. I liked this approach and gave it a try. However, I encountered some issues.
- There is no license given anywhere on the website. Is this sourcecode free to use?
- The example in the article compiles only with clang 3.8.0 (not with gcc 5.3.1) and only with some small modifications (changing "auto v = begin_visitor..." to "auto v = begin_visitor()...").
- Assume my code contains a non-flat graph (e.g. an AST). Some of those nodes in the graph hold references to subnodes. If my visitor traverse such a node, I would like to specify the order of how the subnodes have to be traversed. Is this even possible with this implementation?
Unfortunately the implementation is complicated to understand in depth.
Example:
// define the graph
struct Node {...};
struct Expr : Node {...};
struct Stat : Node {
Expr& sub_node; // introduce a subnode
// ...
}
// now the traversal with the inline visitor
auto v = begin_visitor<NodeVisitor>
.on<Expr>([&](Expr& e)
{
// do something with e
})
.on<Stat>([&](Stat& s)
{
// do something with s
// and then visit the sub_node of type 'Expr':
s.sub_node.accept(*this); // "usual visitor" way: obviously wrong
s.sub_node.accept(v); // cannot use variable in its initialization...
???
})
.end_visitor();
p.accept(v);
I appreciate every comment or hint towards this technique.
Thanks & regards
Aucun commentaire:
Enregistrer un commentaire