From 242512f0dfb5c0a74a33cff75c5742c5ed974fd8 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Mon, 15 Jan 2018 18:57:28 -0800 Subject: [PATCH] Migrate argument_list_is_root out of parse_node_tree_t --- src/highlight.cpp | 8 ++++---- src/parse_tree.cpp | 12 ------------ src/parse_tree.h | 14 +++++++++----- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/highlight.cpp b/src/highlight.cpp index 3d44b1fc1..c7e41548c 100644 --- a/src/highlight.cpp +++ b/src/highlight.cpp @@ -1101,8 +1101,8 @@ const highlighter_t::color_array_t &highlighter_t::highlight() { } // Only work on root lists, so that we don't re-color child lists. case symbol_arguments_or_redirections_list: { - if (parse_tree.argument_list_is_root(node)) { - tnode_t list(&parse_tree, &node); + tnode_t list(&parse_tree, &node); + if (argument_list_is_root(list)) { bool cmd_is_cd = is_cd(list.try_get_parent()); this->color_arguments(list.descendants(), cmd_is_cd); this->color_redirections(list); @@ -1110,8 +1110,8 @@ const highlighter_t::color_array_t &highlighter_t::highlight() { break; } case symbol_argument_list: { - if (parse_tree.argument_list_is_root(node)) { - tnode_t list(&parse_tree, &node); + tnode_t list(&parse_tree, &node); + if (argument_list_is_root(list)) { this->color_arguments(list.descendants()); } break; diff --git a/src/parse_tree.cpp b/src/parse_tree.cpp index 6481e754c..a9e0e48c5 100644 --- a/src/parse_tree.cpp +++ b/src/parse_tree.cpp @@ -1307,18 +1307,6 @@ const parse_node_t *parse_node_tree_t::find_node_matching_source_location( return result; } -bool parse_node_tree_t::argument_list_is_root(const parse_node_t &node) const { - bool result = true; - assert(node.type == symbol_argument_list || node.type == symbol_arguments_or_redirections_list); - const parse_node_t *parent = this->get_parent(node); - if (parent != NULL) { - // We have a parent - check to make sure it's not another list! - result = parent->type != symbol_arguments_or_redirections_list && - parent->type != symbol_argument_list; - } - return result; -} - enum parse_statement_decoration_t get_decoration(tnode_t stmt) { parse_statement_decoration_t decoration = parse_statement_decoration_none; if (auto decorated_statement = stmt.try_get_parent()) { diff --git a/src/parse_tree.h b/src/parse_tree.h index 78f04d1ee..898714070 100644 --- a/src/parse_tree.h +++ b/src/parse_tree.h @@ -188,11 +188,6 @@ class parse_node_tree_t : public std::vector { const parse_node_t *find_node_matching_source_location(parse_token_type_t type, size_t source_loc, const parse_node_t *parent) const; - - // Indicate if the given argument_list or arguments_or_redirections_list is a root list, or has - // a parent. - bool argument_list_is_root(const parse_node_t &node) const; - // Utilities /// Given a plain statement, return true if the statement is part of a pipeline. If @@ -442,6 +437,15 @@ arguments_node_list_t get_argument_nodes(tnode_t); +/// Check whether an argument_list is a root list. +inline bool argument_list_is_root(tnode_t list) { + return !list.try_get_parent(); +} + +inline bool argument_list_is_root(tnode_t list) { + return !list.try_get_parent(); +} + /// The big entry point. Parse a string, attempting to produce a tree for the given goal type. bool parse_tree_from_string(const wcstring &str, parse_tree_flags_t flags, parse_node_tree_t *output, parse_error_list_t *errors,