recursively visit an ast-node
| 11 | |
| 12 | // recursively visit an ast-node |
| 13 | static VISITOR_STRATEGY _AST_Visitor_visit |
| 14 | ( |
| 15 | const cypher_astnode_t *node, |
| 16 | ast_visitor *visitor |
| 17 | ) { |
| 18 | ASSERT(node != NULL); |
| 19 | ASSERT(visitor != NULL); |
| 20 | |
| 21 | // get ast node type |
| 22 | cypher_astnode_type_t node_type = cypher_astnode_type(node); |
| 23 | |
| 24 | //-------------------------------------------------------------------------- |
| 25 | // opening call |
| 26 | //-------------------------------------------------------------------------- |
| 27 | |
| 28 | // first visit of the node |
| 29 | VISITOR_STRATEGY state = visitor->mapping[node_type](node, true, visitor); |
| 30 | if(state != VISITOR_RECURSE) { |
| 31 | // do not visit children |
| 32 | return state; |
| 33 | } |
| 34 | |
| 35 | //-------------------------------------------------------------------------- |
| 36 | // recall for each child node |
| 37 | //-------------------------------------------------------------------------- |
| 38 | |
| 39 | uint nchildren = cypher_astnode_nchildren(node); |
| 40 | for (uint i = 0; i < nchildren; i++) { |
| 41 | if(_AST_Visitor_visit(cypher_astnode_get_child(node, i), visitor) == |
| 42 | VISITOR_BREAK) { |
| 43 | // error occurred, fast fold |
| 44 | return VISITOR_BREAK; |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | //-------------------------------------------------------------------------- |
| 49 | // closing call |
| 50 | //-------------------------------------------------------------------------- |
| 51 | |
| 52 | return visitor->mapping[node_type](node, false, visitor); |
| 53 | } |
| 54 | |
| 55 | // get the context of a visitor |
| 56 | void *AST_Visitor_GetContext |