|
Derived & | derived () |
| Accesses the derived class by static casting the current object. Assumes use of the Curiously Recursive Template Pattern (CRTP). More...
|
|
|
bool | postOrderNodes () const |
| Default behavior option. If true, this results in post-order traversal, where node children are traversed and visited before their parent node. If false, this results in pre-order traversal, where by the current node is visited before the node's children. More...
|
|
bool | reverseChildVisits () const |
| Default behavior option. Reverses the traversal order of child nodes. If true, child nodes are accessed from last to first index .i.e. Node::children() -> 0. If false, child nodes are accessed from first to last .i.e. 0 -> Node::children() More...
|
|
bool | visitNodeHierarchies () const |
| Default behavior option. Controls whether nodes visit themselves at each stage of their class hierarchy. If true, nodes perform multiple visits on their potentially abstract base classes. If false, only the concrete derived types are visited. More...
|
|
bool | reverseHierarchyVisits () const |
| Default behavior option. Reverses the traversal order of node hierarchies. If true, hierarchical visits start at the very top of their inheritance structure (always a Node AST node) and visit downwards until the lowest derived concrete node is reached. If false, hierarchical visits start at the lowest derived concrete node and visit upwards until the very top of their inheritance structure (always a Node AST node) is reached. More...
|
|
|
bool | traverse (NodeType< ast::Tree > *tree) |
| Default traversals for a given concrete AST node type. More...
|
|
bool | traverse (NodeType< ast::StatementList > *cond) |
| Default traversals for a given concrete AST node type. More...
|
|
bool | traverse (NodeType< ast::Block > *block) |
| Default traversals for a given concrete AST node type. More...
|
|
bool | traverse (NodeType< ast::CommaOperator > *comma) |
| Default traversals for a given concrete AST node type. More...
|
|
bool | traverse (NodeType< ast::Loop > *loop) |
| Default traversals for a given concrete AST node type. More...
|
|
bool | traverse (NodeType< ast::Keyword > *keyw) |
| Default traversals for a given concrete AST node type. More...
|
|
bool | traverse (NodeType< ast::ConditionalStatement > *cond) |
| Default traversals for a given concrete AST node type. More...
|
|
bool | traverse (NodeType< ast::AssignExpression > *asgn) |
| Default traversals for a given concrete AST node type. More...
|
|
bool | traverse (NodeType< ast::Crement > *crmt) |
| Default traversals for a given concrete AST node type. More...
|
|
bool | traverse (NodeType< ast::UnaryOperator > *unry) |
| Default traversals for a given concrete AST node type. More...
|
|
bool | traverse (NodeType< ast::BinaryOperator > *bin) |
| Default traversals for a given concrete AST node type. More...
|
|
bool | traverse (NodeType< ast::TernaryOperator > *tern) |
| Default traversals for a given concrete AST node type. More...
|
|
bool | traverse (NodeType< ast::Cast > *cast) |
| Default traversals for a given concrete AST node type. More...
|
|
bool | traverse (NodeType< ast::FunctionCall > *call) |
| Default traversals for a given concrete AST node type. More...
|
|
bool | traverse (NodeType< ast::Attribute > *attr) |
| Default traversals for a given concrete AST node type. More...
|
|
bool | traverse (NodeType< ast::ExternalVariable > *ext) |
| Default traversals for a given concrete AST node type. More...
|
|
bool | traverse (NodeType< ast::DeclareLocal > *decl) |
| Default traversals for a given concrete AST node type. More...
|
|
bool | traverse (NodeType< ast::Local > *loc) |
| Default traversals for a given concrete AST node type. More...
|
|
bool | traverse (NodeType< ast::ArrayPack > *pack) |
| Default traversals for a given concrete AST node type. More...
|
|
bool | traverse (NodeType< ast::ArrayUnpack > *pack) |
| Default traversals for a given concrete AST node type. More...
|
|
bool | traverse (NodeType< ast::Value< bool >> *val) |
| Default traversals for a given concrete AST node type. More...
|
|
bool | traverse (NodeType< ast::Value< int16_t >> *val) |
| Default traversals for a given concrete AST node type. More...
|
|
bool | traverse (NodeType< ast::Value< int32_t >> *val) |
| Default traversals for a given concrete AST node type. More...
|
|
bool | traverse (NodeType< ast::Value< int64_t >> *val) |
| Default traversals for a given concrete AST node type. More...
|
|
bool | traverse (NodeType< ast::Value< float >> *val) |
| Default traversals for a given concrete AST node type. More...
|
|
bool | traverse (NodeType< ast::Value< double >> *val) |
| Default traversals for a given concrete AST node type. More...
|
|
bool | traverse (NodeType< ast::Value< std::string >> *val) |
| Default traversals for a given concrete AST node type. More...
|
|
bool | traverse (NodeType< ast::Node > *node) |
| The default traversal method which is hit for all child traversals. The correct derived traversal scheme is selected by using the node enumerated type. More...
|
|
|
bool | visit (NodeType< ast::Node > *) |
| Visits for abstract (pure-virtual) Node types. More...
|
|
bool | visit (NodeType< ast::Statement > *) |
| Visits for abstract (pure-virtual) Node types. More...
|
|
bool | visit (NodeType< ast::Expression > *) |
| Visits for abstract (pure-virtual) Node types. More...
|
|
bool | visit (NodeType< ast::Variable > *) |
| Visits for abstract (pure-virtual) Node types. More...
|
|
bool | visit (NodeType< ast::ValueBase > *) |
| Visits for abstract (pure-virtual) Node types. More...
|
|
bool | visit (NodeType< ast::Tree > *) |
| Visits for concrete Node types. More...
|
|
bool | visit (NodeType< ast::StatementList > *) |
| Visits for abstract (pure-virtual) Node types. More...
|
|
bool | visit (NodeType< ast::Block > *) |
| Visits for abstract (pure-virtual) Node types. More...
|
|
bool | visit (NodeType< ast::CommaOperator > *) |
| Visits for abstract (pure-virtual) Node types. More...
|
|
bool | visit (NodeType< ast::Loop > *) |
| Visits for abstract (pure-virtual) Node types. More...
|
|
bool | visit (NodeType< ast::Keyword > *) |
| Visits for abstract (pure-virtual) Node types. More...
|
|
bool | visit (NodeType< ast::ConditionalStatement > *) |
| Visits for abstract (pure-virtual) Node types. More...
|
|
bool | visit (NodeType< ast::AssignExpression > *) |
| Visits for abstract (pure-virtual) Node types. More...
|
|
bool | visit (NodeType< ast::Crement > *) |
| Visits for abstract (pure-virtual) Node types. More...
|
|
bool | visit (NodeType< ast::UnaryOperator > *) |
| Visits for abstract (pure-virtual) Node types. More...
|
|
bool | visit (NodeType< ast::BinaryOperator > *) |
| Visits for abstract (pure-virtual) Node types. More...
|
|
bool | visit (NodeType< ast::TernaryOperator > *) |
| Visits for abstract (pure-virtual) Node types. More...
|
|
bool | visit (NodeType< ast::Cast > *) |
| Visits for abstract (pure-virtual) Node types. More...
|
|
bool | visit (NodeType< ast::FunctionCall > *) |
| Visits for abstract (pure-virtual) Node types. More...
|
|
bool | visit (NodeType< ast::Attribute > *) |
| Visits for abstract (pure-virtual) Node types. More...
|
|
bool | visit (NodeType< ast::ExternalVariable > *) |
| Visits for abstract (pure-virtual) Node types. More...
|
|
bool | visit (NodeType< ast::DeclareLocal > *) |
| Visits for abstract (pure-virtual) Node types. More...
|
|
bool | visit (NodeType< ast::Local > *) |
| Visits for abstract (pure-virtual) Node types. More...
|
|
bool | visit (NodeType< ast::ArrayPack > *) |
| Visits for abstract (pure-virtual) Node types. More...
|
|
bool | visit (NodeType< ast::ArrayUnpack > *) |
| Visits for abstract (pure-virtual) Node types. More...
|
|
bool | visit (NodeType< ast::Value< bool >> *) |
| Visits for abstract (pure-virtual) Node types. More...
|
|
bool | visit (NodeType< ast::Value< int16_t >> *) |
| Visits for abstract (pure-virtual) Node types. More...
|
|
bool | visit (NodeType< ast::Value< int32_t >> *) |
| Visits for abstract (pure-virtual) Node types. More...
|
|
bool | visit (NodeType< ast::Value< int64_t >> *) |
| Visits for abstract (pure-virtual) Node types. More...
|
|
bool | visit (NodeType< ast::Value< float >> *) |
| Visits for abstract (pure-virtual) Node types. More...
|
|
bool | visit (NodeType< ast::Value< double >> *) |
| Visits for abstract (pure-virtual) Node types. More...
|
|
bool | visit (NodeType< ast::Value< std::string >> *) |
| Visits for abstract (pure-virtual) Node types. More...
|
|
template<typename Derived, bool ConstVisit = true>
struct openvdb::v12_0::ax::ast::Visitor< Derived, ConstVisit >
The Visitor class uses the Curiously Recursive Template Pattern (CRTP) to provide a customizable interface intended to be used by clients wishing to perform custom operations over an AX Abstract Syntax Tree (AST). By default the Visitor implements simple traversal of all nodes, ensuring that each node on a well formed AST is visited at least once. By deriving from the Visitor, users are able to customize this default behavior and further manually override specific node behavior to their needs. The function options at the top of visitor can be overridden using CRTP to control the prior default behavior, with the ability to override the traverse() and visit() methods for the latter more granular control.
To commence a full visit of an AST, begin by calling traverse() on a Node pointer. A visit is defined as one of the visit() methods being called and accepting a Node type. Each node is is guaranteed to be visited exactly once at its lowest concrete derived type. Node inheritance hierarchies can also be visited (disable by default, see Visitor::visitNodeHierarchies) The traverse() methods define how each AST node accesses its children. The default implementation is for each node to traverses its child pointers in the order returned by the derived Node::child() method (see Visitor::reverseChildVisits). You'll typically only require overriding of the visit() methods for achieving most goals, however you can utilize the traverse methods if you find that you require more control over how the node hierarchy is accessed. The default visit order is post order, where by nodes traverse and visit their children first (see Visitor::postOrderNodes). Each visit method returns a boolean value which, if false, allows for early termination of the traversal. In the below example, we show a Visitor capable of visiting every Local node type exactly once, terminating if the Local variable is called "var".
@par Example:
struct LocalVisitor : public Visitor<LocalVisitor>
{
inline bool visit(
const Local* node) {
if (!node) return true;
if (node->name() == "var") return false;
return true;
}
};
LocalVisitor visitor;
visitor.traverse(&tree);
- Note
- The second template argument, ConstVisit, allows you to perform non-const traversals over the AST. In this case, the visit and traversal function signatures change to non-const pointers.
-
This design is heavily influenced by Clang's RecursiveVisitor.
- Template Parameters
-
Derived | The derived visitor to template on the base visitor, using CRTP |
ConstVisit | Whether to visit const or non-const versions of the AST nodes. Note that this value changes the class function signatures. |