mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 21:33:09 +00:00
Eliminate parse_execution_context_t::get_child
This commit is contained in:
parent
5e4e0dab2c
commit
05e8cf13f7
3 changed files with 12 additions and 12 deletions
|
@ -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<g::job> job_node) const {
|
||||
// Must have one statement.
|
||||
tnode_t<g::statement> 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<grammar::statement> 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<g::job> jo
|
|||
parse_execution_result_t result = parse_execution_success;
|
||||
|
||||
tnode_t<g::statement> 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: {
|
||||
|
|
|
@ -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<grammar::plain_statement> infinite_recursive_statement_in_job_list(
|
||||
tnode_t<grammar::job_list> job_list, wcstring *out_func_name) const;
|
||||
|
|
|
@ -330,6 +330,14 @@ class tnode_t {
|
|||
return tnode_t<child_type>{tree, child};
|
||||
}
|
||||
|
||||
/// Return a parse_node_t for a child.
|
||||
/// This is used to disambiguate alts.
|
||||
template <node_offset_t Index>
|
||||
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<Type, ChildType, 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<Index>();
|
||||
if (child && child->type == ChildType::token) return {tree, child};
|
||||
return {};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue