| 138 | } |
| 139 | |
| 140 | void PreVisitExpr(const Expr* expr, const SourcePosition* position) override { |
| 141 | NavigableProtoAstNode* parent = |
| 142 | parent_stack_.empty() ? nullptr |
| 143 | : metadata_->nodes[parent_stack_.back()].get(); |
| 144 | size_t index = metadata_->nodes.size(); |
| 145 | metadata_->nodes.push_back(node_factory_()); |
| 146 | NavigableProtoAstNode* node = metadata_->nodes[index].get(); |
| 147 | auto& node_data = NodeDataAt(index); |
| 148 | node_data.parent = parent; |
| 149 | node_data.expr = expr; |
| 150 | node_data.parent_relation = ChildKind::kUnspecified; |
| 151 | node_data.node_kind = GetNodeKind(*expr); |
| 152 | node_data.tree_size = 1; |
| 153 | node_data.height = 1; |
| 154 | node_data.index = index; |
| 155 | node_data.child_index = -1; |
| 156 | node_data.metadata = metadata_.get(); |
| 157 | |
| 158 | metadata_->id_to_node.insert({expr->id(), node}); |
| 159 | metadata_->expr_to_node.insert({expr, node}); |
| 160 | if (!parent_stack_.empty()) { |
| 161 | auto& parent_node_data = NodeDataAt(parent_stack_.back()); |
| 162 | size_t child_index = parent_node_data.children.size(); |
| 163 | parent_node_data.children.push_back(node); |
| 164 | node_data.parent_relation = GetChildKind(parent_node_data, child_index); |
| 165 | node_data.child_index = child_index; |
| 166 | } |
| 167 | parent_stack_.push_back(index); |
| 168 | } |
| 169 | |
| 170 | void PostVisitExpr(const Expr* expr, |
| 171 | const SourcePosition* position) override { |
nothing calls this directly
no test coverage detected