From 05e8cf13f7f3d412fede0a345e3bd7e30be5626c Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Mon, 15 Jan 2018 16:18:03 -0800 Subject: [PATCH] Eliminate parse_execution_context_t::get_child --- src/parse_execution.cpp | 12 +++--------- src/parse_execution.h | 2 -- src/parse_tree.h | 10 +++++++++- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/parse_execution.cpp b/src/parse_execution.cpp index 56143b829..54ec5dcea 100644 --- a/src/parse_execution.cpp +++ b/src/parse_execution.cpp @@ -89,12 +89,6 @@ wcstring parse_execution_context_t::get_source(const parse_node_t &node) const { return node.get_source(pstree->src); } -const parse_node_t *parse_execution_context_t::get_child(const parse_node_t &parent, - node_offset_t which, - parse_token_type_t expected_type) const { - return this->tree().get_child(parent, which, expected_type); -} - node_offset_t parse_execution_context_t::get_offset(const parse_node_t &node) const { // Get the offset of a node via pointer arithmetic, very hackish. const parse_node_t *addr = &node; @@ -221,7 +215,7 @@ parse_execution_context_t::cancellation_reason(const block_t *block) const { bool parse_execution_context_t::job_is_simple_block(tnode_t job_node) const { // Must have one statement. tnode_t statement = job_node.child<0>(); - const parse_node_t &specific_statement = *get_child(statement, 0); + const parse_node_t &specific_statement = statement.get_child_node<0>(); if (!specific_statement_type_is_redirectable_block(specific_statement)) { // Not an appropriate block type. return false; @@ -1034,7 +1028,7 @@ parse_execution_result_t parse_execution_context_t::populate_block_process(job_t parse_execution_result_t parse_execution_context_t::populate_job_process( job_t *job, process_t *proc, tnode_t statement) { // Get the "specific statement" which is boolean / block / if / switch / decorated. - const parse_node_t &specific_statement = *get_child(statement, 0); + const parse_node_t &specific_statement = statement.get_child_node<0>(); parse_execution_result_t result = parse_execution_success; @@ -1167,7 +1161,7 @@ parse_execution_result_t parse_execution_context_t::run_1_job(tnode_t jo parse_execution_result_t result = parse_execution_success; tnode_t statement = job_node.child<0>(); - const parse_node_t &specific_statement = *get_child(statement, 0); + const parse_node_t &specific_statement = statement.get_child_node<0>(); assert(specific_statement_type_is_redirectable_block(specific_statement)); switch (specific_statement.type) { case symbol_block_statement: { diff --git a/src/parse_execution.h b/src/parse_execution.h index dcd7638c8..b1553eddc 100644 --- a/src/parse_execution.h +++ b/src/parse_execution.h @@ -70,8 +70,6 @@ class parse_execution_context_t { // Utilities wcstring get_source(const parse_node_t &node) const; - const parse_node_t *get_child(const parse_node_t &parent, node_offset_t which, - parse_token_type_t expected_type = token_type_invalid) const; node_offset_t get_offset(const parse_node_t &node) const; tnode_t infinite_recursive_statement_in_job_list( tnode_t job_list, wcstring *out_func_name) const; diff --git a/src/parse_tree.h b/src/parse_tree.h index 6d2a2bea6..e60fb1d48 100644 --- a/src/parse_tree.h +++ b/src/parse_tree.h @@ -330,6 +330,14 @@ class tnode_t { return tnode_t{tree, child}; } + /// Return a parse_node_t for a child. + /// This is used to disambiguate alts. + template + const parse_node_t &get_child_node() const { + assert(nodeptr && "receiver is missing in get_child_node"); + return *tree->get_child(*nodeptr, Index); + } + /// If the child at the given index has the given type, return it; otherwise return an empty /// child. Note this will refuse to compile if the child type is not possible. /// This is used for e.g. alternations. @@ -338,7 +346,7 @@ class tnode_t { static_assert(child_type_possible_at_index(), "Cannot contain a child of this type"); const parse_node_t *child = nullptr; - if (nodeptr) child = tree->get_child(*nodeptr, Index); + if (nodeptr) child = &get_child_node(); if (child && child->type == ChildType::token) return {tree, child}; return {}; }