1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 10:47:35 +00:00

Everywhere: Stop using NonnullRefPtrVector

This class had slightly confusing semantics and the added weirdness
doesn't seem worth it just so we can say "." instead of "->" when
iterating over a vector of NNRPs.

This patch replaces NonnullRefPtrVector<T> with Vector<NNRP<T>>.
This commit is contained in:
Andreas Kling 2023-03-06 14:17:01 +01:00
parent 104be6c8ac
commit 8a48246ed1
168 changed files with 1280 additions and 1280 deletions

View file

@ -48,7 +48,7 @@ ErrorOr<void> AK::Formatter<Shell::AST::Command>::format(FormatBuilder& builder,
for (auto& redir : value.redirections) {
TRY(builder.put_padding(' ', 1));
if (redir.is_path_redirection()) {
if (redir->is_path_redirection()) {
auto path_redir = (Shell::AST::PathRedirection const*)&redir;
TRY(builder.put_i64(path_redir->fd));
switch (path_redir->direction) {
@ -66,12 +66,12 @@ ErrorOr<void> AK::Formatter<Shell::AST::Command>::format(FormatBuilder& builder,
break;
}
TRY(builder.put_literal(path_redir->path));
} else if (redir.is_fd_redirection()) {
} else if (redir->is_fd_redirection()) {
auto* fdredir = (Shell::AST::FdRedirection const*)&redir;
TRY(builder.put_i64(fdredir->new_fd));
TRY(builder.put_literal(">"sv));
TRY(builder.put_i64(fdredir->old_fd));
} else if (redir.is_close_redirection()) {
} else if (redir->is_close_redirection()) {
auto close_redir = (Shell::AST::CloseRedirection const*)&redir;
TRY(builder.put_i64(close_redir->fd));
TRY(builder.put_literal(">&-"sv));
@ -156,18 +156,18 @@ static inline Vector<Command> join_commands(Vector<Command> left, Vector<Command
return commands;
}
static ErrorOr<String> resolve_slices(RefPtr<Shell> shell, String&& input_value, NonnullRefPtrVector<Slice> slices)
static ErrorOr<String> resolve_slices(RefPtr<Shell> shell, String&& input_value, Vector<NonnullRefPtr<Slice>> slices)
{
if (slices.is_empty())
return move(input_value);
for (auto& slice : slices) {
auto value = TRY(slice.run(shell));
auto value = TRY(slice->run(shell));
if (shell && shell->has_any_error())
break;
if (!value) {
shell->raise_error(Shell::ShellError::InvalidSliceContentsError, "Invalid slice contents", slice.position());
shell->raise_error(Shell::ShellError::InvalidSliceContentsError, "Invalid slice contents", slice->position());
return move(input_value);
}
@ -179,7 +179,7 @@ static ErrorOr<String> resolve_slices(RefPtr<Shell> shell, String&& input_value,
for (auto& value : index_values) {
auto maybe_index = value.bytes_as_string_view().to_int();
if (!maybe_index.has_value()) {
shell->raise_error(Shell::ShellError::InvalidSliceContentsError, DeprecatedString::formatted("Invalid value in slice index {}: {} (expected a number)", i, value), slice.position());
shell->raise_error(Shell::ShellError::InvalidSliceContentsError, DeprecatedString::formatted("Invalid value in slice index {}: {} (expected a number)", i, value), slice->position());
return move(input_value);
}
++i;
@ -190,7 +190,7 @@ static ErrorOr<String> resolve_slices(RefPtr<Shell> shell, String&& input_value,
index += input_value.bytes_as_string_view().length();
if (index < 0 || (size_t)index >= input_value.bytes_as_string_view().length()) {
shell->raise_error(Shell::ShellError::InvalidSliceContentsError, DeprecatedString::formatted("Slice index {} (evaluated as {}) out of value bounds [0-{})", index, original_index, input_value.bytes_as_string_view().length()), slice.position());
shell->raise_error(Shell::ShellError::InvalidSliceContentsError, DeprecatedString::formatted("Slice index {} (evaluated as {}) out of value bounds [0-{})", index, original_index, input_value.bytes_as_string_view().length()), slice->position());
return move(input_value);
}
indices.unchecked_append(index);
@ -206,18 +206,18 @@ static ErrorOr<String> resolve_slices(RefPtr<Shell> shell, String&& input_value,
return move(input_value);
}
static ErrorOr<Vector<String>> resolve_slices(RefPtr<Shell> shell, Vector<String>&& values, NonnullRefPtrVector<Slice> slices)
static ErrorOr<Vector<String>> resolve_slices(RefPtr<Shell> shell, Vector<String>&& values, Vector<NonnullRefPtr<Slice>> slices)
{
if (slices.is_empty())
return move(values);
for (auto& slice : slices) {
auto value = TRY(slice.run(shell));
auto value = TRY(slice->run(shell));
if (shell && shell->has_any_error())
break;
if (!value) {
shell->raise_error(Shell::ShellError::InvalidSliceContentsError, "Invalid slice contents", slice.position());
shell->raise_error(Shell::ShellError::InvalidSliceContentsError, "Invalid slice contents", slice->position());
return move(values);
}
@ -229,7 +229,7 @@ static ErrorOr<Vector<String>> resolve_slices(RefPtr<Shell> shell, Vector<String
for (auto& value : index_values) {
auto maybe_index = value.bytes_as_string_view().to_int();
if (!maybe_index.has_value()) {
shell->raise_error(Shell::ShellError::InvalidSliceContentsError, DeprecatedString::formatted("Invalid value in slice index {}: {} (expected a number)", i, value), slice.position());
shell->raise_error(Shell::ShellError::InvalidSliceContentsError, DeprecatedString::formatted("Invalid value in slice index {}: {} (expected a number)", i, value), slice->position());
return move(values);
}
++i;
@ -240,7 +240,7 @@ static ErrorOr<Vector<String>> resolve_slices(RefPtr<Shell> shell, Vector<String
index += values.size();
if (index < 0 || (size_t)index >= values.size()) {
shell->raise_error(Shell::ShellError::InvalidSliceContentsError, DeprecatedString::formatted("Slice index {} (evaluated as {}) out of value bounds [0-{})", index, original_index, values.size()), slice.position());
shell->raise_error(Shell::ShellError::InvalidSliceContentsError, DeprecatedString::formatted("Slice index {} (evaluated as {}) out of value bounds [0-{})", index, original_index, values.size()), slice->position());
return move(values);
}
indices.unchecked_append(index);
@ -505,7 +505,7 @@ ErrorOr<RefPtr<Value>> ListConcatenate::run(RefPtr<Shell> shell)
result = make_ref_counted<CommandSequenceValue>(move(joined_commands));
}
} else {
NonnullRefPtrVector<Value> values;
Vector<NonnullRefPtr<Value>> values;
if (result->is_list_without_resolution()) {
values.extend(static_cast<ListValue*>(result.ptr())->values());
@ -695,17 +695,17 @@ ErrorOr<void> BraceExpansion::dump(int level) const
{
TRY(Node::dump(level));
for (auto& entry : m_entries)
TRY(entry.dump(level + 1));
TRY(entry->dump(level + 1));
return {};
}
ErrorOr<RefPtr<Value>> BraceExpansion::run(RefPtr<Shell> shell)
{
NonnullRefPtrVector<Value> values;
Vector<NonnullRefPtr<Value>> values;
for (auto& entry : m_entries) {
if (shell && shell->has_any_error())
break;
auto value = TRY(entry.run(shell));
auto value = TRY(entry->run(shell));
if (value)
values.append(value.release_nonnull());
}
@ -716,10 +716,10 @@ ErrorOr<RefPtr<Value>> BraceExpansion::run(RefPtr<Shell> shell)
HitTestResult BraceExpansion::hit_test_position(size_t offset) const
{
for (auto& entry : m_entries) {
auto result = entry.hit_test_position(offset);
auto result = entry->hit_test_position(offset);
if (result.matching_node) {
if (!result.closest_command_node)
result.closest_command_node = &entry;
result.closest_command_node = entry;
return result;
}
}
@ -730,20 +730,20 @@ HitTestResult BraceExpansion::hit_test_position(size_t offset) const
ErrorOr<void> BraceExpansion::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata)
{
for (auto& entry : m_entries) {
TRY(entry.highlight_in_editor(editor, shell, metadata));
TRY(entry->highlight_in_editor(editor, shell, metadata));
metadata.is_first_in_list = false;
}
return {};
}
BraceExpansion::BraceExpansion(Position position, NonnullRefPtrVector<Node> entries)
BraceExpansion::BraceExpansion(Position position, Vector<NonnullRefPtr<Node>> entries)
: Node(move(position))
, m_entries(move(entries))
{
for (auto& entry : m_entries) {
if (entry.is_syntax_error()) {
set_is_syntax_error(entry.syntax_error_node());
if (entry->is_syntax_error()) {
set_is_syntax_error(entry->syntax_error_node());
break;
}
}
@ -838,7 +838,7 @@ ErrorOr<RefPtr<Value>> CastToList::run(RefPtr<Shell> shell)
return inner_value;
auto values = TRY(inner_value->resolve_as_list(shell));
NonnullRefPtrVector<Value> cast_values;
Vector<NonnullRefPtr<Value>> cast_values;
for (auto& value : values)
cast_values.append(make_ref_counted<StringValue>(value));
@ -1663,7 +1663,7 @@ ErrorOr<RefPtr<Value>> HistoryEvent::run(RefPtr<Shell> shell)
shell->raise_error(Shell::ShellError::EvaluatedSyntaxError, "History word index out of bounds", m_selector.word_selector_range.start.position);
return make_ref_counted<AST::ListValue>({});
}
return nodes[index].run(shell);
return nodes[index]->run(shell);
}
ErrorOr<void> HistoryEvent::highlight_in_editor(Line::Editor& editor, Shell&, HighlightMetadata metadata)
@ -1832,9 +1832,9 @@ ErrorOr<void> Execute::for_each_entry(RefPtr<Shell> shell, Function<ErrorOr<Iter
auto jobs = shell->run_commands(commands);
ScopeGuard kill_jobs_if_around { [&] {
for (auto& job : jobs) {
if (job.is_running_in_background() && !job.exited() && !job.signaled()) {
job.set_should_announce_signal(false); // We're explicitly killing it here.
shell->kill_job(&job, SIGTERM);
if (job->is_running_in_background() && !job->exited() && !job->signaled()) {
job->set_should_announce_signal(false); // We're explicitly killing it here.
shell->kill_job(job, SIGTERM);
}
}
} };
@ -1873,7 +1873,7 @@ ErrorOr<void> Execute::for_each_entry(RefPtr<Shell> shell, Function<ErrorOr<Iter
auto jobs = shell->run_commands(commands);
if (!jobs.is_empty())
TRY(callback(make_ref_counted<JobValue>(&jobs.last())));
TRY(callback(make_ref_counted<JobValue>(jobs.last())));
return {};
}
@ -1886,13 +1886,13 @@ ErrorOr<RefPtr<Value>> Execute::run(RefPtr<Shell> shell)
if (m_command->would_execute())
return m_command->run(shell);
NonnullRefPtrVector<Value> values;
Vector<NonnullRefPtr<Value>> values;
TRY(for_each_entry(shell, [&](auto value) {
values.append(*value);
return IterationDecision::Continue;
}));
if (values.size() == 1 && values.first().is_job())
if (values.size() == 1 && values.first()->is_job())
return values.first();
return make_ref_counted<ListValue>(move(values));
@ -2065,7 +2065,7 @@ ErrorOr<void> ImmediateExpression::dump(int level) const
print_indented(level + 2, "{}", m_function.name);
print_indented(level + 1, "(arguments)");
for (auto& argument : arguments())
TRY(argument.dump(level + 2));
TRY(argument->dump(level + 2));
return {};
}
@ -2093,7 +2093,7 @@ ErrorOr<void> ImmediateExpression::highlight_in_editor(Line::Editor& editor, She
// Arguments
for (auto& argument : m_arguments) {
metadata.is_first_in_list = false;
TRY(argument.highlight_in_editor(editor, shell, metadata));
TRY(argument->highlight_in_editor(editor, shell, metadata));
}
// Closing brace
@ -2123,14 +2123,14 @@ HitTestResult ImmediateExpression::hit_test_position(size_t offset) const
return { this, this, this };
for (auto& argument : m_arguments) {
if (auto result = argument.hit_test_position(offset); result.matching_node)
if (auto result = argument->hit_test_position(offset); result.matching_node)
return result;
}
return {};
}
ImmediateExpression::ImmediateExpression(Position position, NameWithPosition function, NonnullRefPtrVector<AST::Node> arguments, Optional<Position> closing_brace_position)
ImmediateExpression::ImmediateExpression(Position position, NameWithPosition function, Vector<NonnullRefPtr<AST::Node>> arguments, Optional<Position> closing_brace_position)
: Node(move(position))
, m_arguments(move(arguments))
, m_function(move(function))
@ -2140,8 +2140,8 @@ ImmediateExpression::ImmediateExpression(Position position, NameWithPosition fun
return;
for (auto& argument : m_arguments) {
if (argument.is_syntax_error()) {
set_is_syntax_error(argument.syntax_error_node());
if (argument->is_syntax_error()) {
set_is_syntax_error(argument->syntax_error_node());
return;
}
}
@ -2244,9 +2244,9 @@ ErrorOr<void> MatchExpr::dump(int level) const
}
print_indented(level + 2, "{}", builder.string_view());
TRY(entry.options.visit(
[&](NonnullRefPtrVector<Node> const& options) -> ErrorOr<void> {
[&](Vector<NonnullRefPtr<Node>> const& options) -> ErrorOr<void> {
for (auto& option : options)
TRY(option.dump(level + 3));
TRY(option->dump(level + 3));
return {};
},
[&](Vector<Regex<ECMA262>> const& options) -> ErrorOr<void> {
@ -2307,17 +2307,17 @@ ErrorOr<RefPtr<Value>> MatchExpr::run(RefPtr<Shell> shell)
return ErrorOr<Regex<ECMA262>>(move(option));
} else {
Vector<String> pattern;
if (option.is_glob()) {
pattern.append(static_cast<const Glob*>(&option)->text());
} else if (option.is_bareword()) {
pattern.append(static_cast<const BarewordLiteral*>(&option)->text());
if (option->is_glob()) {
pattern.append(static_cast<Glob const*>(option.ptr())->text());
} else if (option->is_bareword()) {
pattern.append(static_cast<BarewordLiteral const*>(option.ptr())->text());
} else {
auto list_or_error = option.run(shell);
auto list_or_error = option->run(shell);
if (list_or_error.is_error() || (shell && shell->has_any_error()))
return ErrorOr<Vector<String>>(move(pattern));
auto list = list_or_error.release_value();
auto result = option.for_each_entry(shell, [&](auto&& value) -> ErrorOr<IterationDecision> {
auto result = option->for_each_entry(shell, [&](auto&& value) -> ErrorOr<IterationDecision> {
pattern.extend(TRY(value->resolve_as_list(nullptr))); // Note: 'nullptr' incurs special behavior,
// asking the node for a 'raw' value.
return IterationDecision::Continue;
@ -2379,9 +2379,9 @@ ErrorOr<void> MatchExpr::highlight_in_editor(Line::Editor& editor, Shell& shell,
for (auto& entry : m_entries) {
metadata.is_first_in_list = false;
TRY(entry.options.visit(
[&](NonnullRefPtrVector<Node>& node_options) -> ErrorOr<void> {
[&](Vector<NonnullRefPtr<Node>>& node_options) -> ErrorOr<void> {
for (auto& option : node_options)
TRY(option.highlight_in_editor(editor, shell, metadata));
TRY(option->highlight_in_editor(editor, shell, metadata));
return {};
},
[](auto&) -> ErrorOr<void> { return {}; }));
@ -2526,9 +2526,9 @@ ErrorOr<RefPtr<Value>> Pipe::run(RefPtr<Shell> shell)
auto& redirections = command.redirections;
for (ssize_t i = redirections.size() - 1; i >= 0; --i) {
auto& redirection = redirections[i];
if (!redirection.is_fd_redirection())
if (!redirection->is_fd_redirection())
continue;
auto& fd_redirection = static_cast<FdRedirection&>(redirection);
auto& fd_redirection = static_cast<FdRedirection&>(*redirection);
if (fd_redirection.old_fd == -1) {
insert_index = i;
break;
@ -2663,8 +2663,8 @@ ErrorOr<void> Range::dump(int level) const
ErrorOr<RefPtr<Value>> Range::run(RefPtr<Shell> shell)
{
auto interpolate = [position = position()](RefPtr<Value> start, RefPtr<Value> end, RefPtr<Shell> shell) -> NonnullRefPtrVector<Value> {
NonnullRefPtrVector<Value> values;
auto interpolate = [position = position()](RefPtr<Value> start, RefPtr<Value> end, RefPtr<Shell> shell) -> Vector<NonnullRefPtr<Value>> {
Vector<NonnullRefPtr<Value>> values;
if (start->is_string() && end->is_string()) {
auto start_str = start->resolve_as_list(shell).release_value_but_fixme_should_propagate_errors()[0];
@ -2839,7 +2839,7 @@ ErrorOr<void> Sequence::dump(int level) const
{
TRY(Node::dump(level));
for (auto& entry : m_entries)
TRY(entry.dump(level + 1));
TRY(entry->dump(level + 1));
return {};
}
@ -2851,7 +2851,7 @@ ErrorOr<RefPtr<Value>> Sequence::run(RefPtr<Shell> shell)
if (shell && shell->has_any_error())
break;
if (!last_command_in_sequence) {
auto commands = TRY(entry.to_lazy_evaluated_commands(shell));
auto commands = TRY(entry->to_lazy_evaluated_commands(shell));
all_commands.extend(move(commands));
last_command_in_sequence = &all_commands.last();
continue;
@ -2860,7 +2860,7 @@ ErrorOr<RefPtr<Value>> Sequence::run(RefPtr<Shell> shell)
if (last_command_in_sequence->should_wait) {
last_command_in_sequence->next_chain.append(NodeWithAction { entry, NodeWithAction::Sequence });
} else {
all_commands.extend(TRY(entry.to_lazy_evaluated_commands(shell)));
all_commands.extend(TRY(entry->to_lazy_evaluated_commands(shell)));
last_command_in_sequence = &all_commands.last();
}
}
@ -2871,14 +2871,14 @@ ErrorOr<RefPtr<Value>> Sequence::run(RefPtr<Shell> shell)
ErrorOr<void> Sequence::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata)
{
for (auto& entry : m_entries)
TRY(entry.highlight_in_editor(editor, shell, metadata));
TRY(entry->highlight_in_editor(editor, shell, metadata));
return {};
}
HitTestResult Sequence::hit_test_position(size_t offset) const
{
for (auto& entry : m_entries) {
auto result = entry.hit_test_position(offset);
auto result = entry->hit_test_position(offset);
if (result.matching_node) {
if (!result.closest_command_node)
result.closest_command_node = entry;
@ -2892,20 +2892,20 @@ HitTestResult Sequence::hit_test_position(size_t offset) const
RefPtr<Node const> Sequence::leftmost_trivial_literal() const
{
for (auto& entry : m_entries) {
if (auto node = entry.leftmost_trivial_literal())
if (auto node = entry->leftmost_trivial_literal())
return node;
}
return nullptr;
}
Sequence::Sequence(Position position, NonnullRefPtrVector<Node> entries, Vector<Position> separator_positions)
Sequence::Sequence(Position position, Vector<NonnullRefPtr<Node>> entries, Vector<Position> separator_positions)
: Node(move(position))
, m_entries(move(entries))
, m_separator_positions(separator_positions)
{
for (auto& entry : m_entries) {
if (entry.is_syntax_error()) {
set_is_syntax_error(entry.syntax_error_node());
if (entry->is_syntax_error()) {
set_is_syntax_error(entry->syntax_error_node());
break;
}
}
@ -3669,7 +3669,7 @@ ErrorOr<NonnullRefPtr<Value>> Value::with_slices(NonnullRefPtr<Slice> slice) con
return value;
}
ErrorOr<NonnullRefPtr<Value>> Value::with_slices(NonnullRefPtrVector<Slice> slices) const&
ErrorOr<NonnullRefPtr<Value>> Value::with_slices(Vector<NonnullRefPtr<Slice>> slices) const&
{
auto value = TRY(clone());
value->m_slices.extend(move(slices));
@ -3684,16 +3684,16 @@ ErrorOr<Vector<String>> ListValue::resolve_as_list(RefPtr<Shell> shell)
{
Vector<String> values;
for (auto& value : m_contained_values)
values.extend(TRY(value.resolve_as_list(shell)));
values.extend(TRY(value->resolve_as_list(shell)));
return resolve_slices(shell, move(values), m_slices);
}
ErrorOr<NonnullRefPtr<Value>> ListValue::resolve_without_cast(RefPtr<Shell> shell)
{
NonnullRefPtrVector<Value> values;
Vector<NonnullRefPtr<Value>> values;
for (auto& value : m_contained_values)
values.append(TRY(value.resolve_without_cast(shell)));
values.append(TRY(value->resolve_without_cast(shell)));
NonnullRefPtr<Value> value = make_ref_counted<ListValue>(move(values));
if (!m_slices.is_empty())

View file

@ -208,7 +208,7 @@ struct NodeWithAction {
struct Command {
Vector<String> argv;
NonnullRefPtrVector<Redirection> redirections;
Vector<NonnullRefPtr<Redirection>> redirections;
bool should_wait { true };
bool is_pipe_source { false };
bool should_notify_if_in_background { true };
@ -233,7 +233,7 @@ public:
virtual ErrorOr<NonnullRefPtr<Value>> resolve_without_cast(RefPtr<Shell>) { return *this; }
virtual ErrorOr<NonnullRefPtr<Value>> clone() const = 0;
virtual ErrorOr<NonnullRefPtr<Value>> with_slices(NonnullRefPtr<Slice> slice) const&;
virtual ErrorOr<NonnullRefPtr<Value>> with_slices(NonnullRefPtrVector<Slice> slices) const&;
virtual ErrorOr<NonnullRefPtr<Value>> with_slices(Vector<NonnullRefPtr<Slice>> slices) const&;
virtual ~Value();
virtual bool is_command() const { return false; }
virtual bool is_glob() const { return false; }
@ -243,12 +243,12 @@ public:
virtual bool is_list_without_resolution() const { return false; }
protected:
Value& set_slices(NonnullRefPtrVector<Slice> slices)
Value& set_slices(Vector<NonnullRefPtr<Slice>> slices)
{
m_slices = move(slices);
return *this;
}
NonnullRefPtrVector<Slice> m_slices;
Vector<NonnullRefPtr<Slice>> m_slices;
};
class CommandValue final : public Value {
@ -316,16 +316,16 @@ public:
virtual bool is_list() const override { return true; }
virtual bool is_list_without_resolution() const override { return true; }
ListValue(Vector<String> values);
ListValue(NonnullRefPtrVector<Value> values)
ListValue(Vector<NonnullRefPtr<Value>> values)
: m_contained_values(move(values))
{
}
NonnullRefPtrVector<Value> const& values() const { return m_contained_values; }
NonnullRefPtrVector<Value>& values() { return m_contained_values; }
Vector<NonnullRefPtr<Value>> const& values() const { return m_contained_values; }
Vector<NonnullRefPtr<Value>>& values() { return m_contained_values; }
private:
NonnullRefPtrVector<Value> m_contained_values;
Vector<NonnullRefPtr<Value>> m_contained_values;
};
class StringValue final : public Value {
@ -629,11 +629,11 @@ private:
class BraceExpansion final : public Node {
public:
BraceExpansion(Position, NonnullRefPtrVector<Node>);
BraceExpansion(Position, Vector<NonnullRefPtr<Node>>);
virtual ~BraceExpansion() = default;
virtual void visit(NodeVisitor& visitor) override { visitor.visit(this); }
NonnullRefPtrVector<Node> const& entries() const { return m_entries; }
Vector<NonnullRefPtr<Node>> const& entries() const { return m_entries; }
private:
NODE(BraceExpansion);
@ -642,7 +642,7 @@ private:
virtual ErrorOr<void> highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override;
virtual HitTestResult hit_test_position(size_t) const override;
NonnullRefPtrVector<Node> m_entries;
Vector<NonnullRefPtr<Node>> m_entries;
};
class CastToCommand final : public Node {
@ -1019,11 +1019,11 @@ private:
class ImmediateExpression final : public Node {
public:
ImmediateExpression(Position, NameWithPosition function, NonnullRefPtrVector<AST::Node> arguments, Optional<Position> closing_brace_position);
ImmediateExpression(Position, NameWithPosition function, Vector<NonnullRefPtr<AST::Node>> arguments, Optional<Position> closing_brace_position);
virtual ~ImmediateExpression();
virtual void visit(NodeVisitor& visitor) override { visitor.visit(this); }
NonnullRefPtrVector<Node> const& arguments() const { return m_arguments; }
Vector<NonnullRefPtr<Node>> const& arguments() const { return m_arguments; }
auto const& function() const { return m_function; }
String const& function_name() const { return m_function.name; }
Position const& function_position() const { return m_function.position; }
@ -1037,7 +1037,7 @@ private:
ErrorOr<Vector<Line::CompletionSuggestion>> complete_for_editor(Shell&, size_t, HitTestResult const&) const override;
virtual HitTestResult hit_test_position(size_t) const override;
NonnullRefPtrVector<AST::Node> m_arguments;
Vector<NonnullRefPtr<AST::Node>> m_arguments;
NameWithPosition m_function;
Optional<Position> m_closing_brace_position;
};
@ -1066,7 +1066,7 @@ private:
};
struct MatchEntry {
Variant<NonnullRefPtrVector<Node>, Vector<Regex<ECMA262>>> options;
Variant<Vector<NonnullRefPtr<Node>>, Vector<Regex<ECMA262>>> options;
Optional<Vector<String>> match_names;
Optional<Position> match_as_position;
Vector<Position> pipe_positions;
@ -1188,11 +1188,11 @@ private:
class Sequence final : public Node {
public:
Sequence(Position, NonnullRefPtrVector<Node>, Vector<Position> separator_positions);
Sequence(Position, Vector<NonnullRefPtr<Node>>, Vector<Position> separator_positions);
virtual ~Sequence();
virtual void visit(NodeVisitor& visitor) override { visitor.visit(this); }
NonnullRefPtrVector<Node> const& entries() const { return m_entries; }
Vector<NonnullRefPtr<Node>> const& entries() const { return m_entries; }
Vector<Position> const& separator_positions() const { return m_separator_positions; }
@ -1206,7 +1206,7 @@ private:
virtual bool should_override_execution_in_current_process() const override { return true; }
virtual RefPtr<Node const> leftmost_trivial_literal() const override;
NonnullRefPtrVector<Node> m_entries;
Vector<NonnullRefPtr<Node>> m_entries;
Vector<Position> m_separator_positions;
};

View file

@ -1014,7 +1014,7 @@ ErrorOr<int> Shell::builtin_time(Main::Arguments arguments)
auto timer = Core::ElapsedTimer::start_new();
for (auto& job : run_commands(commands)) {
block_on_job(job);
exit_code = job.exit_code();
exit_code = job->exit_code();
}
iteration_times.add(static_cast<float>(timer.elapsed()));
}
@ -1190,7 +1190,7 @@ ErrorOr<int> Shell::builtin_not(Main::Arguments arguments)
for (auto& job : run_commands(commands)) {
found_a_job = true;
block_on_job(job);
exit_code = job.exit_code();
exit_code = job->exit_code();
}
// In case it was a function.
if (!found_a_job)
@ -1242,7 +1242,7 @@ ErrorOr<int> Shell::builtin_kill(Main::Arguments arguments)
return exit_code;
}
ErrorOr<bool> Shell::run_builtin(const AST::Command& command, NonnullRefPtrVector<AST::Rewiring> const& rewirings, int& retval)
ErrorOr<bool> Shell::run_builtin(const AST::Command& command, Vector<NonnullRefPtr<AST::Rewiring>> const& rewirings, int& retval)
{
if (command.argv.is_empty())
return false;
@ -1266,7 +1266,7 @@ ErrorOr<bool> Shell::run_builtin(const AST::Command& command, NonnullRefPtrVecto
SavedFileDescriptors fds { rewirings };
for (auto& rewiring : rewirings) {
int rc = dup2(rewiring.old_fd, rewiring.new_fd);
int rc = dup2(rewiring->old_fd, rewiring->new_fd);
if (rc < 0) {
perror("dup2(run)");
return false;

View file

@ -29,7 +29,7 @@ private:
class SavedFileDescriptors {
public:
SavedFileDescriptors(NonnullRefPtrVector<AST::Rewiring> const&);
SavedFileDescriptors(Vector<NonnullRefPtr<AST::Rewiring>> const&);
~SavedFileDescriptors();
private:

View file

@ -204,7 +204,7 @@ void Formatter::visit(const AST::BraceExpansion* node)
if (!first)
current_builder().append(',');
first = false;
entry.visit(*this);
entry->visit(*this);
}
}
@ -529,7 +529,7 @@ void Formatter::visit(const AST::ImmediateExpression* node)
for (auto& node : node->arguments()) {
current_builder().append(' ');
node.visit(*this);
node->visit(*this);
}
if (node->has_closing_brace())
@ -585,12 +585,12 @@ void Formatter::visit(const AST::MatchExpr* node)
first_entry = false;
auto first = true;
entry.options.visit(
[&](NonnullRefPtrVector<AST::Node> const& patterns) {
[&](Vector<NonnullRefPtr<AST::Node>> const& patterns) {
for (auto& option : patterns) {
if (!first)
current_builder().append(" | "sv);
first = false;
option.visit(*this);
option->visit(*this);
}
},
[&](Vector<Regex<ECMA262>> const& patterns) {
@ -721,7 +721,7 @@ void Formatter::visit(const AST::Sequence* node)
else
insert_separator();
entry.visit(*this);
entry->visit(*this);
}
visited(node);

View file

@ -10,7 +10,7 @@
namespace Shell {
ErrorOr<RefPtr<AST::Node>> Shell::immediate_length_impl(AST::ImmediateExpression& invoking_node, NonnullRefPtrVector<AST::Node> const& arguments, bool across)
ErrorOr<RefPtr<AST::Node>> Shell::immediate_length_impl(AST::ImmediateExpression& invoking_node, Vector<NonnullRefPtr<AST::Node>> const& arguments, bool across)
{
auto name = across ? "length_across" : "length";
if (arguments.size() < 1 || arguments.size() > 2) {
@ -32,12 +32,12 @@ ErrorOr<RefPtr<AST::Node>> Shell::immediate_length_impl(AST::ImmediateExpression
// length list <expr>
auto& mode_arg = arguments.first();
if (!mode_arg.is_bareword()) {
raise_error(ShellError::EvaluatedSyntaxError, DeprecatedString::formatted("Expected a bareword (either 'string' or 'list') in the two-argument form of the `{}' immediate", name), mode_arg.position());
if (!mode_arg->is_bareword()) {
raise_error(ShellError::EvaluatedSyntaxError, DeprecatedString::formatted("Expected a bareword (either 'string' or 'list') in the two-argument form of the `{}' immediate", name), mode_arg->position());
return nullptr;
}
auto const& mode_name = static_cast<const AST::BarewordLiteral&>(mode_arg).text();
auto const& mode_name = static_cast<const AST::BarewordLiteral&>(*mode_arg).text();
if (mode_name == "list") {
mode = List;
} else if (mode_name == "string") {
@ -45,13 +45,13 @@ ErrorOr<RefPtr<AST::Node>> Shell::immediate_length_impl(AST::ImmediateExpression
} else if (mode_name == "infer") {
mode = Infer;
} else {
raise_error(ShellError::EvaluatedSyntaxError, DeprecatedString::formatted("Expected either 'string' or 'list' (and not {}) in the two-argument form of the `{}' immediate", mode_name, name), mode_arg.position());
raise_error(ShellError::EvaluatedSyntaxError, DeprecatedString::formatted("Expected either 'string' or 'list' (and not {}) in the two-argument form of the `{}' immediate", mode_name, name), mode_arg->position());
return nullptr;
}
expr_node = &arguments[1];
expr_node = arguments[1];
} else {
expr_node = &arguments[0];
expr_node = arguments[0];
}
if (mode == Infer) {
@ -81,7 +81,7 @@ ErrorOr<RefPtr<AST::Node>> Shell::immediate_length_impl(AST::ImmediateExpression
resulting_nodes.unchecked_append(AST::make_ref_counted<AST::ImmediateExpression>(
expr_node->position(),
AST::NameWithPosition { TRY("length"_string), invoking_node.function_position() },
NonnullRefPtrVector<AST::Node> { Vector<NonnullRefPtr<AST::Node>> {
Vector<NonnullRefPtr<AST::Node>> { Vector<NonnullRefPtr<AST::Node>> {
static_cast<NonnullRefPtr<AST::Node>>(AST::make_ref_counted<AST::BarewordLiteral>(expr_node->position(), TRY(String::from_utf8(mode_name)))),
AST::make_ref_counted<AST::SyntheticNode>(expr_node->position(), NonnullRefPtr<AST::Value>(entry)),
} },
@ -189,39 +189,39 @@ ErrorOr<RefPtr<AST::Node>> Shell::immediate_length_impl(AST::ImmediateExpression
}
}
ErrorOr<RefPtr<AST::Node>> Shell::immediate_length(AST::ImmediateExpression& invoking_node, NonnullRefPtrVector<AST::Node> const& arguments)
ErrorOr<RefPtr<AST::Node>> Shell::immediate_length(AST::ImmediateExpression& invoking_node, Vector<NonnullRefPtr<AST::Node>> const& arguments)
{
return immediate_length_impl(invoking_node, arguments, false);
}
ErrorOr<RefPtr<AST::Node>> Shell::immediate_length_across(AST::ImmediateExpression& invoking_node, NonnullRefPtrVector<AST::Node> const& arguments)
ErrorOr<RefPtr<AST::Node>> Shell::immediate_length_across(AST::ImmediateExpression& invoking_node, Vector<NonnullRefPtr<AST::Node>> const& arguments)
{
return immediate_length_impl(invoking_node, arguments, true);
}
ErrorOr<RefPtr<AST::Node>> Shell::immediate_regex_replace(AST::ImmediateExpression& invoking_node, NonnullRefPtrVector<AST::Node> const& arguments)
ErrorOr<RefPtr<AST::Node>> Shell::immediate_regex_replace(AST::ImmediateExpression& invoking_node, Vector<NonnullRefPtr<AST::Node>> const& arguments)
{
if (arguments.size() != 3) {
raise_error(ShellError::EvaluatedSyntaxError, "Expected exactly 3 arguments to regex_replace", invoking_node.position());
return nullptr;
}
auto pattern = TRY(const_cast<AST::Node&>(arguments[0]).run(this));
auto replacement = TRY(const_cast<AST::Node&>(arguments[1]).run(this));
auto value = TRY(TRY(const_cast<AST::Node&>(arguments[2]).run(this))->resolve_without_cast(this));
auto pattern = TRY(const_cast<AST::Node&>(*arguments[0]).run(this));
auto replacement = TRY(const_cast<AST::Node&>(*arguments[1]).run(this));
auto value = TRY(TRY(const_cast<AST::Node&>(*arguments[2]).run(this))->resolve_without_cast(this));
if (!pattern->is_string()) {
raise_error(ShellError::EvaluatedSyntaxError, "Expected the regex_replace pattern to be a string", arguments[0].position());
raise_error(ShellError::EvaluatedSyntaxError, "Expected the regex_replace pattern to be a string", arguments[0]->position());
return nullptr;
}
if (!replacement->is_string()) {
raise_error(ShellError::EvaluatedSyntaxError, "Expected the regex_replace replacement string to be a string", arguments[1].position());
raise_error(ShellError::EvaluatedSyntaxError, "Expected the regex_replace replacement string to be a string", arguments[1]->position());
return nullptr;
}
if (!value->is_string()) {
raise_error(ShellError::EvaluatedSyntaxError, "Expected the regex_replace target value to be a string", arguments[2].position());
raise_error(ShellError::EvaluatedSyntaxError, "Expected the regex_replace target value to be a string", arguments[2]->position());
return nullptr;
}
@ -234,18 +234,18 @@ ErrorOr<RefPtr<AST::Node>> Shell::immediate_regex_replace(AST::ImmediateExpressi
return AST::make_ref_counted<AST::StringLiteral>(invoking_node.position(), TRY(String::from_utf8(result)), AST::StringLiteral::EnclosureType::None);
}
ErrorOr<RefPtr<AST::Node>> Shell::immediate_remove_suffix(AST::ImmediateExpression& invoking_node, NonnullRefPtrVector<AST::Node> const& arguments)
ErrorOr<RefPtr<AST::Node>> Shell::immediate_remove_suffix(AST::ImmediateExpression& invoking_node, Vector<NonnullRefPtr<AST::Node>> const& arguments)
{
if (arguments.size() != 2) {
raise_error(ShellError::EvaluatedSyntaxError, "Expected exactly 2 arguments to remove_suffix", invoking_node.position());
return nullptr;
}
auto suffix = TRY(const_cast<AST::Node&>(arguments[0]).run(this));
auto value = TRY(TRY(const_cast<AST::Node&>(arguments[1]).run(this))->resolve_without_cast(this));
auto suffix = TRY(const_cast<AST::Node&>(*arguments[0]).run(this));
auto value = TRY(TRY(const_cast<AST::Node&>(*arguments[1]).run(this))->resolve_without_cast(this));
if (!suffix->is_string()) {
raise_error(ShellError::EvaluatedSyntaxError, "Expected the remove_suffix suffix string to be a string", arguments[0].position());
raise_error(ShellError::EvaluatedSyntaxError, "Expected the remove_suffix suffix string to be a string", arguments[0]->position());
return nullptr;
}
@ -266,18 +266,18 @@ ErrorOr<RefPtr<AST::Node>> Shell::immediate_remove_suffix(AST::ImmediateExpressi
return AST::make_ref_counted<AST::ListConcatenate>(invoking_node.position(), move(nodes));
}
ErrorOr<RefPtr<AST::Node>> Shell::immediate_remove_prefix(AST::ImmediateExpression& invoking_node, NonnullRefPtrVector<AST::Node> const& arguments)
ErrorOr<RefPtr<AST::Node>> Shell::immediate_remove_prefix(AST::ImmediateExpression& invoking_node, Vector<NonnullRefPtr<AST::Node>> const& arguments)
{
if (arguments.size() != 2) {
raise_error(ShellError::EvaluatedSyntaxError, "Expected exactly 2 arguments to remove_prefix", invoking_node.position());
return nullptr;
}
auto prefix = TRY(const_cast<AST::Node&>(arguments[0]).run(this));
auto value = TRY(TRY(const_cast<AST::Node&>(arguments[1]).run(this))->resolve_without_cast(this));
auto prefix = TRY(const_cast<AST::Node&>(*arguments[0]).run(this));
auto value = TRY(TRY(const_cast<AST::Node&>(*arguments[1]).run(this))->resolve_without_cast(this));
if (!prefix->is_string()) {
raise_error(ShellError::EvaluatedSyntaxError, "Expected the remove_prefix prefix string to be a string", arguments[0].position());
raise_error(ShellError::EvaluatedSyntaxError, "Expected the remove_prefix prefix string to be a string", arguments[0]->position());
return nullptr;
}
@ -297,18 +297,18 @@ ErrorOr<RefPtr<AST::Node>> Shell::immediate_remove_prefix(AST::ImmediateExpressi
return AST::make_ref_counted<AST::ListConcatenate>(invoking_node.position(), move(nodes));
}
ErrorOr<RefPtr<AST::Node>> Shell::immediate_split(AST::ImmediateExpression& invoking_node, NonnullRefPtrVector<AST::Node> const& arguments)
ErrorOr<RefPtr<AST::Node>> Shell::immediate_split(AST::ImmediateExpression& invoking_node, Vector<NonnullRefPtr<AST::Node>> const& arguments)
{
if (arguments.size() != 2) {
raise_error(ShellError::EvaluatedSyntaxError, "Expected exactly 2 arguments to split", invoking_node.position());
return nullptr;
}
auto delimiter = TRY(const_cast<AST::Node&>(arguments[0]).run(this));
auto value = TRY(TRY(const_cast<AST::Node&>(arguments[1]).run(this))->resolve_without_cast(this));
auto delimiter = TRY(const_cast<AST::Node&>(*arguments[0]).run(this));
auto value = TRY(TRY(const_cast<AST::Node&>(*arguments[1]).run(this))->resolve_without_cast(this));
if (!delimiter->is_string()) {
raise_error(ShellError::EvaluatedSyntaxError, "Expected the split delimiter string to be a string", arguments[0].position());
raise_error(ShellError::EvaluatedSyntaxError, "Expected the split delimiter string to be a string", arguments[0]->position());
return nullptr;
}
@ -321,13 +321,13 @@ ErrorOr<RefPtr<AST::Node>> Shell::immediate_split(AST::ImmediateExpression& invo
for (auto& entry : values) {
// ImmediateExpression(split <delimiter> <entry>)
resulting_nodes.unchecked_append(AST::make_ref_counted<AST::ImmediateExpression>(
arguments[1].position(),
arguments[1]->position(),
invoking_node.function(),
NonnullRefPtrVector<AST::Node> { Vector<NonnullRefPtr<AST::Node>> {
Vector<NonnullRefPtr<AST::Node>> { Vector<NonnullRefPtr<AST::Node>> {
arguments[0],
AST::make_ref_counted<AST::SyntheticNode>(arguments[1].position(), NonnullRefPtr<AST::Value>(entry)),
AST::make_ref_counted<AST::SyntheticNode>(arguments[1]->position(), NonnullRefPtr<AST::Value>(entry)),
} },
arguments[1].position()));
arguments[1]->position()));
}
return AST::make_ref_counted<AST::ListConcatenate>(invoking_node.position(), move(resulting_nodes));
@ -341,7 +341,7 @@ ErrorOr<RefPtr<AST::Node>> Shell::immediate_split(AST::ImmediateExpression& invo
auto list = TRY(value->resolve_as_list(this));
if (!value->is_list()) {
if (list.is_empty())
return AST::make_ref_counted<AST::ListConcatenate>(invoking_node.position(), NonnullRefPtrVector<AST::Node> {});
return AST::make_ref_counted<AST::ListConcatenate>(invoking_node.position(), Vector<NonnullRefPtr<AST::Node>> {});
auto& value = list.first();
Vector<String> split_strings;
@ -364,22 +364,22 @@ ErrorOr<RefPtr<AST::Node>> Shell::immediate_split(AST::ImmediateExpression& invo
return transform(AST::make_ref_counted<AST::ListValue>(list)->values());
}
ErrorOr<RefPtr<AST::Node>> Shell::immediate_concat_lists(AST::ImmediateExpression& invoking_node, NonnullRefPtrVector<AST::Node> const& arguments)
ErrorOr<RefPtr<AST::Node>> Shell::immediate_concat_lists(AST::ImmediateExpression& invoking_node, Vector<NonnullRefPtr<AST::Node>> const& arguments)
{
NonnullRefPtrVector<AST::Node> result;
Vector<NonnullRefPtr<AST::Node>> result;
for (auto& argument : arguments) {
if (auto* list = dynamic_cast<const AST::ListConcatenate*>(&argument)) {
if (auto* list = dynamic_cast<AST::ListConcatenate const*>(argument.ptr())) {
result.extend(list->list());
} else {
auto list_of_values = TRY(TRY(const_cast<AST::Node&>(argument).run(this))->resolve_without_cast(this));
auto list_of_values = TRY(TRY(const_cast<AST::Node&>(*argument).run(this))->resolve_without_cast(this));
if (auto* list = dynamic_cast<AST::ListValue*>(list_of_values.ptr())) {
for (auto& entry : static_cast<Vector<NonnullRefPtr<AST::Value>>&>(list->values()))
result.append(AST::make_ref_counted<AST::SyntheticNode>(argument.position(), entry));
result.append(AST::make_ref_counted<AST::SyntheticNode>(argument->position(), entry));
} else {
auto values = TRY(list_of_values->resolve_as_list(this));
for (auto& entry : values)
result.append(AST::make_ref_counted<AST::StringLiteral>(argument.position(), entry, AST::StringLiteral::EnclosureType::None));
result.append(AST::make_ref_counted<AST::StringLiteral>(argument->position(), entry, AST::StringLiteral::EnclosureType::None));
}
}
}
@ -387,7 +387,7 @@ ErrorOr<RefPtr<AST::Node>> Shell::immediate_concat_lists(AST::ImmediateExpressio
return AST::make_ref_counted<AST::ListConcatenate>(invoking_node.position(), move(result));
}
ErrorOr<RefPtr<AST::Node>> Shell::immediate_filter_glob(AST::ImmediateExpression& invoking_node, NonnullRefPtrVector<AST::Node> const& arguments)
ErrorOr<RefPtr<AST::Node>> Shell::immediate_filter_glob(AST::ImmediateExpression& invoking_node, Vector<NonnullRefPtr<AST::Node>> const& arguments)
{
// filter_glob string list
if (arguments.size() != 2) {
@ -395,33 +395,33 @@ ErrorOr<RefPtr<AST::Node>> Shell::immediate_filter_glob(AST::ImmediateExpression
return nullptr;
}
auto glob_list = TRY(TRY(const_cast<AST::Node&>(arguments[0]).run(*this))->resolve_as_list(*this));
auto glob_list = TRY(TRY(const_cast<AST::Node&>(*arguments[0]).run(*this))->resolve_as_list(*this));
if (glob_list.size() != 1) {
raise_error(ShellError::EvaluatedSyntaxError, "Expected the <glob> argument to filter_glob to be a single string", arguments[0].position());
raise_error(ShellError::EvaluatedSyntaxError, "Expected the <glob> argument to filter_glob to be a single string", arguments[0]->position());
return nullptr;
}
auto& glob = glob_list.first();
auto& list_node = arguments[1];
NonnullRefPtrVector<AST::Node> result;
Vector<NonnullRefPtr<AST::Node>> result;
TRY(const_cast<AST::Node&>(list_node).for_each_entry(*this, [&](NonnullRefPtr<AST::Value> entry) -> ErrorOr<IterationDecision> {
TRY(const_cast<AST::Node&>(*list_node).for_each_entry(*this, [&](NonnullRefPtr<AST::Value> entry) -> ErrorOr<IterationDecision> {
auto value = TRY(entry->resolve_as_list(*this));
if (value.size() == 0)
return IterationDecision::Continue;
if (value.size() == 1) {
if (!value.first().bytes_as_string_view().matches(glob))
return IterationDecision::Continue;
result.append(AST::make_ref_counted<AST::StringLiteral>(arguments[1].position(), value.first(), AST::StringLiteral::EnclosureType::None));
result.append(AST::make_ref_counted<AST::StringLiteral>(arguments[1]->position(), value.first(), AST::StringLiteral::EnclosureType::None));
return IterationDecision::Continue;
}
for (auto& entry : value) {
if (entry.bytes_as_string_view().matches(glob)) {
NonnullRefPtrVector<AST::Node> nodes;
Vector<NonnullRefPtr<AST::Node>> nodes;
for (auto& string : value)
nodes.append(AST::make_ref_counted<AST::StringLiteral>(arguments[1].position(), string, AST::StringLiteral::EnclosureType::None));
result.append(AST::make_ref_counted<AST::ListConcatenate>(arguments[1].position(), move(nodes)));
nodes.append(AST::make_ref_counted<AST::StringLiteral>(arguments[1]->position(), string, AST::StringLiteral::EnclosureType::None));
result.append(AST::make_ref_counted<AST::ListConcatenate>(arguments[1]->position(), move(nodes)));
return IterationDecision::Continue;
}
}
@ -431,22 +431,22 @@ ErrorOr<RefPtr<AST::Node>> Shell::immediate_filter_glob(AST::ImmediateExpression
return AST::make_ref_counted<AST::ListConcatenate>(invoking_node.position(), move(result));
}
ErrorOr<RefPtr<AST::Node>> Shell::immediate_join(AST::ImmediateExpression& invoking_node, NonnullRefPtrVector<AST::Node> const& arguments)
ErrorOr<RefPtr<AST::Node>> Shell::immediate_join(AST::ImmediateExpression& invoking_node, Vector<NonnullRefPtr<AST::Node>> const& arguments)
{
if (arguments.size() != 2) {
raise_error(ShellError::EvaluatedSyntaxError, "Expected exactly 2 arguments to join", invoking_node.position());
return nullptr;
}
auto delimiter = TRY(const_cast<AST::Node&>(arguments[0]).run(this));
auto delimiter = TRY(const_cast<AST::Node&>(*arguments[0]).run(this));
if (!delimiter->is_string()) {
raise_error(ShellError::EvaluatedSyntaxError, "Expected the join delimiter string to be a string", arguments[0].position());
raise_error(ShellError::EvaluatedSyntaxError, "Expected the join delimiter string to be a string", arguments[0]->position());
return nullptr;
}
auto value = TRY(TRY(const_cast<AST::Node&>(arguments[1]).run(this))->resolve_without_cast(this));
auto value = TRY(TRY(const_cast<AST::Node&>(*arguments[1]).run(this))->resolve_without_cast(this));
if (!value->is_list()) {
raise_error(ShellError::EvaluatedSyntaxError, "Expected the joined list to be a list", arguments[1].position());
raise_error(ShellError::EvaluatedSyntaxError, "Expected the joined list to be a list", arguments[1]->position());
return nullptr;
}
@ -457,49 +457,49 @@ ErrorOr<RefPtr<AST::Node>> Shell::immediate_join(AST::ImmediateExpression& invok
return AST::make_ref_counted<AST::StringLiteral>(invoking_node.position(), TRY(builder.to_string()), AST::StringLiteral::EnclosureType::None);
}
ErrorOr<RefPtr<AST::Node>> Shell::immediate_value_or_default(AST::ImmediateExpression& invoking_node, NonnullRefPtrVector<AST::Node> const& arguments)
ErrorOr<RefPtr<AST::Node>> Shell::immediate_value_or_default(AST::ImmediateExpression& invoking_node, Vector<NonnullRefPtr<AST::Node>> const& arguments)
{
if (arguments.size() != 2) {
raise_error(ShellError::EvaluatedSyntaxError, "Expected exactly 2 arguments to value_or_default", invoking_node.position());
return nullptr;
}
auto name = TRY(TRY(const_cast<AST::Node&>(arguments.first()).run(*this))->resolve_as_string(*this));
auto name = TRY(TRY(const_cast<AST::Node&>(*arguments.first()).run(*this))->resolve_as_string(*this));
if (!TRY(local_variable_or(name, ""sv)).is_empty())
return make_ref_counted<AST::SimpleVariable>(invoking_node.position(), name);
return arguments.last();
}
ErrorOr<RefPtr<AST::Node>> Shell::immediate_assign_default(AST::ImmediateExpression& invoking_node, NonnullRefPtrVector<AST::Node> const& arguments)
ErrorOr<RefPtr<AST::Node>> Shell::immediate_assign_default(AST::ImmediateExpression& invoking_node, Vector<NonnullRefPtr<AST::Node>> const& arguments)
{
if (arguments.size() != 2) {
raise_error(ShellError::EvaluatedSyntaxError, "Expected exactly 2 arguments to assign_default", invoking_node.position());
return nullptr;
}
auto name = TRY(TRY(const_cast<AST::Node&>(arguments.first()).run(*this))->resolve_as_string(*this));
auto name = TRY(TRY(const_cast<AST::Node&>(*arguments.first()).run(*this))->resolve_as_string(*this));
if (!TRY(local_variable_or(name, ""sv)).is_empty())
return make_ref_counted<AST::SimpleVariable>(invoking_node.position(), name);
auto value = TRY(TRY(const_cast<AST::Node&>(arguments.last()).run(*this))->resolve_without_cast(*this));
auto value = TRY(TRY(const_cast<AST::Node&>(*arguments.last()).run(*this))->resolve_without_cast(*this));
set_local_variable(name.to_deprecated_string(), value);
return make_ref_counted<AST::SyntheticNode>(invoking_node.position(), value);
}
ErrorOr<RefPtr<AST::Node>> Shell::immediate_error_if_empty(AST::ImmediateExpression& invoking_node, NonnullRefPtrVector<AST::Node> const& arguments)
ErrorOr<RefPtr<AST::Node>> Shell::immediate_error_if_empty(AST::ImmediateExpression& invoking_node, Vector<NonnullRefPtr<AST::Node>> const& arguments)
{
if (arguments.size() != 2) {
raise_error(ShellError::EvaluatedSyntaxError, "Expected exactly 2 arguments to error_if_empty", invoking_node.position());
return nullptr;
}
auto name = TRY(TRY(const_cast<AST::Node&>(arguments.first()).run(*this))->resolve_as_string(*this));
auto name = TRY(TRY(const_cast<AST::Node&>(*arguments.first()).run(*this))->resolve_as_string(*this));
if (!TRY(local_variable_or(name, ""sv)).is_empty())
return make_ref_counted<AST::SimpleVariable>(invoking_node.position(), name);
auto error_value = TRY(TRY(const_cast<AST::Node&>(arguments.last()).run(*this))->resolve_as_string(*this));
auto error_value = TRY(TRY(const_cast<AST::Node&>(*arguments.last()).run(*this))->resolve_as_string(*this));
if (error_value.is_empty())
error_value = TRY(String::formatted("Expected {} to be non-empty", name));
@ -507,63 +507,63 @@ ErrorOr<RefPtr<AST::Node>> Shell::immediate_error_if_empty(AST::ImmediateExpress
return nullptr;
}
ErrorOr<RefPtr<AST::Node>> Shell::immediate_null_or_alternative(AST::ImmediateExpression& invoking_node, NonnullRefPtrVector<AST::Node> const& arguments)
ErrorOr<RefPtr<AST::Node>> Shell::immediate_null_or_alternative(AST::ImmediateExpression& invoking_node, Vector<NonnullRefPtr<AST::Node>> const& arguments)
{
if (arguments.size() != 2) {
raise_error(ShellError::EvaluatedSyntaxError, "Expected exactly 2 arguments to null_or_alternative", invoking_node.position());
return nullptr;
}
auto value = TRY(TRY(const_cast<AST::Node&>(arguments.first()).run(*this))->resolve_without_cast(*this));
auto value = TRY(TRY(const_cast<AST::Node&>(*arguments.first()).run(*this))->resolve_without_cast(*this));
if ((value->is_string() && TRY(value->resolve_as_string(*this)).is_empty()) || (value->is_list() && TRY(value->resolve_as_list(*this)).is_empty()))
return make_ref_counted<AST::SyntheticNode>(invoking_node.position(), value);
return arguments.last();
}
ErrorOr<RefPtr<AST::Node>> Shell::immediate_defined_value_or_default(AST::ImmediateExpression& invoking_node, NonnullRefPtrVector<AST::Node> const& arguments)
ErrorOr<RefPtr<AST::Node>> Shell::immediate_defined_value_or_default(AST::ImmediateExpression& invoking_node, Vector<NonnullRefPtr<AST::Node>> const& arguments)
{
if (arguments.size() != 2) {
raise_error(ShellError::EvaluatedSyntaxError, "Expected exactly 2 arguments to defined_value_or_default", invoking_node.position());
return nullptr;
}
auto name = TRY(TRY(const_cast<AST::Node&>(arguments.first()).run(*this))->resolve_as_string(*this));
auto name = TRY(TRY(const_cast<AST::Node&>(*arguments.first()).run(*this))->resolve_as_string(*this));
if (!find_frame_containing_local_variable(name))
return arguments.last();
return make_ref_counted<AST::SimpleVariable>(invoking_node.position(), name);
}
ErrorOr<RefPtr<AST::Node>> Shell::immediate_assign_defined_default(AST::ImmediateExpression& invoking_node, NonnullRefPtrVector<AST::Node> const& arguments)
ErrorOr<RefPtr<AST::Node>> Shell::immediate_assign_defined_default(AST::ImmediateExpression& invoking_node, Vector<NonnullRefPtr<AST::Node>> const& arguments)
{
if (arguments.size() != 2) {
raise_error(ShellError::EvaluatedSyntaxError, "Expected exactly 2 arguments to assign_defined_default", invoking_node.position());
return nullptr;
}
auto name = TRY(TRY(const_cast<AST::Node&>(arguments.first()).run(*this))->resolve_as_string(*this));
auto name = TRY(TRY(const_cast<AST::Node&>(*arguments.first()).run(*this))->resolve_as_string(*this));
if (find_frame_containing_local_variable(name))
return make_ref_counted<AST::SimpleVariable>(invoking_node.position(), name);
auto value = TRY(TRY(const_cast<AST::Node&>(arguments.last()).run(*this))->resolve_without_cast(*this));
auto value = TRY(TRY(const_cast<AST::Node&>(*arguments.last()).run(*this))->resolve_without_cast(*this));
set_local_variable(name.to_deprecated_string(), value);
return make_ref_counted<AST::SyntheticNode>(invoking_node.position(), value);
}
ErrorOr<RefPtr<AST::Node>> Shell::immediate_error_if_unset(AST::ImmediateExpression& invoking_node, NonnullRefPtrVector<AST::Node> const& arguments)
ErrorOr<RefPtr<AST::Node>> Shell::immediate_error_if_unset(AST::ImmediateExpression& invoking_node, Vector<NonnullRefPtr<AST::Node>> const& arguments)
{
if (arguments.size() != 2) {
raise_error(ShellError::EvaluatedSyntaxError, "Expected exactly 2 arguments to error_if_unset", invoking_node.position());
return nullptr;
}
auto name = TRY(TRY(const_cast<AST::Node&>(arguments.first()).run(*this))->resolve_as_string(*this));
auto name = TRY(TRY(const_cast<AST::Node&>(*arguments.first()).run(*this))->resolve_as_string(*this));
if (find_frame_containing_local_variable(name))
return make_ref_counted<AST::SimpleVariable>(invoking_node.position(), name);
auto error_value = TRY(TRY(const_cast<AST::Node&>(arguments.last()).run(*this))->resolve_as_string(*this));
auto error_value = TRY(TRY(const_cast<AST::Node&>(*arguments.last()).run(*this))->resolve_as_string(*this));
if (error_value.is_empty())
error_value = TRY(String::formatted("Expected {} to be set", name));
@ -571,39 +571,39 @@ ErrorOr<RefPtr<AST::Node>> Shell::immediate_error_if_unset(AST::ImmediateExpress
return nullptr;
}
ErrorOr<RefPtr<AST::Node>> Shell::immediate_null_if_unset_or_alternative(AST::ImmediateExpression& invoking_node, NonnullRefPtrVector<AST::Node> const& arguments)
ErrorOr<RefPtr<AST::Node>> Shell::immediate_null_if_unset_or_alternative(AST::ImmediateExpression& invoking_node, Vector<NonnullRefPtr<AST::Node>> const& arguments)
{
if (arguments.size() != 2) {
raise_error(ShellError::EvaluatedSyntaxError, "Expected exactly 2 arguments to null_if_unset_or_alternative", invoking_node.position());
return nullptr;
}
auto name = TRY(TRY(const_cast<AST::Node&>(arguments.first()).run(*this))->resolve_as_string(*this));
auto name = TRY(TRY(const_cast<AST::Node&>(*arguments.first()).run(*this))->resolve_as_string(*this));
if (!find_frame_containing_local_variable(name))
return arguments.last();
return make_ref_counted<AST::SimpleVariable>(invoking_node.position(), name);
}
ErrorOr<RefPtr<AST::Node>> Shell::immediate_reexpand(AST::ImmediateExpression& invoking_node, NonnullRefPtrVector<AST::Node> const& arguments)
ErrorOr<RefPtr<AST::Node>> Shell::immediate_reexpand(AST::ImmediateExpression& invoking_node, Vector<NonnullRefPtr<AST::Node>> const& arguments)
{
if (arguments.size() != 1) {
raise_error(ShellError::EvaluatedSyntaxError, "Expected exactly 1 argument to reexpand", invoking_node.position());
return nullptr;
}
auto value = TRY(TRY(const_cast<AST::Node&>(arguments.first()).run(*this))->resolve_as_string(*this));
auto value = TRY(TRY(const_cast<AST::Node&>(*arguments.first()).run(*this))->resolve_as_string(*this));
return parse(value, m_is_interactive, false);
}
ErrorOr<RefPtr<AST::Node>> Shell::immediate_length_of_variable(AST::ImmediateExpression& invoking_node, NonnullRefPtrVector<AST::Node> const& arguments)
ErrorOr<RefPtr<AST::Node>> Shell::immediate_length_of_variable(AST::ImmediateExpression& invoking_node, Vector<NonnullRefPtr<AST::Node>> const& arguments)
{
if (arguments.size() != 1) {
raise_error(ShellError::EvaluatedSyntaxError, "Expected exactly 1 argument to length_of_variable", invoking_node.position());
return nullptr;
}
auto name = TRY(TRY(const_cast<AST::Node&>(arguments.first()).run(*this))->resolve_as_string(*this));
auto name = TRY(TRY(const_cast<AST::Node&>(*arguments.first()).run(*this))->resolve_as_string(*this));
auto variable = make_ref_counted<AST::SimpleVariable>(invoking_node.position(), name);
return immediate_length_impl(
@ -612,7 +612,7 @@ ErrorOr<RefPtr<AST::Node>> Shell::immediate_length_of_variable(AST::ImmediateExp
false);
}
ErrorOr<RefPtr<AST::Node>> Shell::run_immediate_function(StringView str, AST::ImmediateExpression& invoking_node, NonnullRefPtrVector<AST::Node> const& arguments)
ErrorOr<RefPtr<AST::Node>> Shell::run_immediate_function(StringView str, AST::ImmediateExpression& invoking_node, Vector<NonnullRefPtr<AST::Node>> const& arguments)
{
#define __ENUMERATE_SHELL_IMMEDIATE_FUNCTION(name) \
if (str == #name) \

View file

@ -38,7 +38,7 @@ void NodeVisitor::visit(const AST::BarewordLiteral*)
void NodeVisitor::visit(const AST::BraceExpansion* node)
{
for (auto& entry : node->entries())
entry.visit(*this);
entry->visit(*this);
}
void NodeVisitor::visit(const AST::CastToCommand* node)
@ -128,7 +128,7 @@ void NodeVisitor::visit(const AST::IfCond* node)
void NodeVisitor::visit(const AST::ImmediateExpression* node)
{
for (auto& node : node->arguments())
node.visit(*this);
node->visit(*this);
}
void NodeVisitor::visit(const AST::Join* node)
@ -141,9 +141,9 @@ void NodeVisitor::visit(const AST::MatchExpr* node)
{
node->matched_expr()->visit(*this);
for (auto& entry : node->entries()) {
if (auto* ptr = entry.options.get_pointer<NonnullRefPtrVector<Node>>()) {
if (auto* ptr = entry.options.get_pointer<Vector<NonnullRefPtr<Node>>>()) {
for (auto& option : *ptr)
option.visit(*this);
option->visit(*this);
}
if (entry.body)
entry.body->visit(*this);
@ -181,7 +181,7 @@ void NodeVisitor::visit(const AST::ReadWriteRedirection* node)
void NodeVisitor::visit(const AST::Sequence* node)
{
for (auto& entry : node->entries())
entry.visit(*this);
entry->visit(*this);
}
void NodeVisitor::visit(const AST::Subshell* node)

View file

@ -149,9 +149,9 @@ RefPtr<AST::Node> Parser::parse_as_single_expression()
return parser.parse_expression();
}
NonnullRefPtrVector<AST::Node> Parser::parse_as_multiple_expressions()
Vector<NonnullRefPtr<AST::Node>> Parser::parse_as_multiple_expressions()
{
NonnullRefPtrVector<AST::Node> nodes;
Vector<NonnullRefPtr<AST::Node>> nodes;
for (;;) {
consume_while(is_whitespace);
auto node = parse_expression();
@ -168,7 +168,7 @@ RefPtr<AST::Node> Parser::parse_toplevel()
auto rule_start = push_start();
SequenceParseResult result;
NonnullRefPtrVector<AST::Node> sequence;
Vector<NonnullRefPtr<AST::Node>> sequence;
Vector<AST::Position> positions;
do {
result = parse_sequence();
@ -188,7 +188,7 @@ RefPtr<AST::Node> Parser::parse_toplevel()
Parser::SequenceParseResult Parser::parse_sequence()
{
NonnullRefPtrVector<AST::Node> left;
Vector<NonnullRefPtr<AST::Node>> left;
auto read_terminators = [&](bool consider_tabs_and_spaces) {
if (m_heredoc_initiations.is_empty()) {
discard_terminators:;
@ -927,7 +927,7 @@ AST::MatchEntry Parser::parse_match_entry()
{
auto rule_start = push_start();
NonnullRefPtrVector<AST::Node> patterns;
Vector<NonnullRefPtr<AST::Node>> patterns;
Vector<Regex<ECMA262>> regexps;
Vector<AST::Position> pipe_positions;
Optional<Vector<String>> match_names;
@ -942,14 +942,14 @@ AST::MatchEntry Parser::parse_match_entry()
auto regex_pattern = parse_regex_pattern();
if (regex_pattern.has_value()) {
if (auto error = regex_pattern.value().parser_result.error; error != regex::Error::NoError)
return { NonnullRefPtrVector<AST::Node> {}, {}, {}, {}, create<AST::SyntaxError>(String::from_utf8(regex::get_error_string(error)).release_value_but_fixme_should_propagate_errors(), false) };
return { Vector<NonnullRefPtr<AST::Node>> {}, {}, {}, {}, create<AST::SyntaxError>(String::from_utf8(regex::get_error_string(error)).release_value_but_fixme_should_propagate_errors(), false) };
pattern_kind = Regex;
regexps.append(regex_pattern.release_value());
} else {
auto glob_pattern = parse_match_pattern();
if (!glob_pattern)
return { NonnullRefPtrVector<AST::Node> {}, {}, {}, {}, create<AST::SyntaxError>("Expected a pattern in 'match' body"_string.release_value_but_fixme_should_propagate_errors(), true) };
return { Vector<NonnullRefPtr<AST::Node>> {}, {}, {}, {}, create<AST::SyntaxError>("Expected a pattern in 'match' body"_string.release_value_but_fixme_should_propagate_errors(), true) };
pattern_kind = Glob;
patterns.append(glob_pattern.release_nonnull());
@ -1633,7 +1633,7 @@ RefPtr<AST::Node> Parser::parse_immediate_expression()
consume_while(is_whitespace);
NonnullRefPtrVector<AST::Node> arguments;
Vector<NonnullRefPtr<AST::Node>> arguments;
do {
auto expr = parse_expression();
if (!expr)
@ -2021,7 +2021,7 @@ RefPtr<AST::Node> Parser::parse_brace_expansion_spec()
m_extra_chars_not_allowed_in_barewords.append(',');
auto rule_start = push_start();
NonnullRefPtrVector<AST::Node> subexpressions;
Vector<NonnullRefPtr<AST::Node>> subexpressions;
if (next_is(","sv)) {
// Note that we don't consume the ',' here.

View file

@ -27,7 +27,7 @@ public:
/// Parse the given string *as* an expression
/// that is to forcefully enclose it in double-quotes.
RefPtr<AST::Node> parse_as_single_expression();
NonnullRefPtrVector<AST::Node> parse_as_multiple_expressions();
Vector<NonnullRefPtr<AST::Node>> parse_as_multiple_expressions();
struct SavedOffset {
size_t offset;
@ -47,7 +47,7 @@ private:
};
struct SequenceParseResult {
NonnullRefPtrVector<AST::Node> entries;
Vector<NonnullRefPtr<AST::Node>> entries;
Vector<AST::Position, 1> separator_positions;
ShouldReadMoreSequences decision;
};

View file

@ -663,7 +663,7 @@ ErrorOr<RefPtr<AST::Node>> Parser::parse_complete_command()
ErrorOr<RefPtr<AST::Node>> Parser::parse_list()
{
NonnullRefPtrVector<AST::Node> nodes;
Vector<NonnullRefPtr<AST::Node>> nodes;
Vector<AST::Position> positions;
auto start_position = peek().position.value_or(empty_position());
@ -1120,7 +1120,7 @@ ErrorOr<RefPtr<AST::Node>> Parser::parse_case_clause()
ErrorOr<Parser::CaseItemsResult> Parser::parse_case_list()
{
// Just a list of words split by '|', delimited by ')'
NonnullRefPtrVector<AST::Node> nodes;
Vector<NonnullRefPtr<AST::Node>> nodes;
Vector<AST::Position> pipes;
for (;;) {
@ -1291,7 +1291,7 @@ ErrorOr<RefPtr<AST::Node>> Parser::parse_compound_list()
ErrorOr<RefPtr<AST::Node>> Parser::parse_term()
{
NonnullRefPtrVector<AST::Node> nodes;
Vector<NonnullRefPtr<AST::Node>> nodes;
Vector<AST::Position> positions;
auto start_position = peek().position.value_or(empty_position());
@ -1381,7 +1381,7 @@ ErrorOr<RefPtr<AST::Node>> Parser::parse_for_clause()
RefPtr<AST::Node> Parser::parse_word_list()
{
NonnullRefPtrVector<AST::Node> nodes;
Vector<NonnullRefPtr<AST::Node>> nodes;
auto start_position = peek().position.value_or(empty_position());
@ -1568,7 +1568,7 @@ ErrorOr<RefPtr<AST::Node>> Parser::parse_word()
}
if (!node) {
NonnullRefPtrVector<AST::Node> arguments;
Vector<NonnullRefPtr<AST::Node>> arguments;
arguments.append(make_ref_counted<AST::BarewordLiteral>(
token.position.value_or(empty_position()),
x.parameter));
@ -1787,7 +1787,7 @@ ErrorOr<RefPtr<AST::Node>> Parser::parse_simple_command()
auto start_position = peek().position.value_or(empty_position());
Vector<String> definitions;
NonnullRefPtrVector<AST::Node> nodes;
Vector<NonnullRefPtr<AST::Node>> nodes;
for (;;) {
if (auto io_redirect = TRY(parse_io_redirect()))
@ -1858,7 +1858,7 @@ ErrorOr<RefPtr<AST::Node>> Parser::parse_simple_command()
// "substitute_aliases"sv,
// empty_position(),
// },
// NonnullRefPtrVector<AST::Node> { *new_word },
// Vector<NonnullRefPtr<AST::Node>> { *new_word },
// Optional<AST::Position> {});
// }

View file

@ -63,7 +63,7 @@ private:
struct CaseItemsResult {
Vector<AST::Position> pipe_positions;
NonnullRefPtrVector<AST::Node> nodes;
Vector<NonnullRefPtr<AST::Node>> nodes;
};
ErrorOr<RefPtr<AST::Node>> parse_complete_command();

View file

@ -634,9 +634,9 @@ ErrorOr<RefPtr<Job>> Shell::run_command(const AST::Command& command)
}
// Resolve redirections.
NonnullRefPtrVector<AST::Rewiring> rewirings;
Vector<NonnullRefPtr<AST::Rewiring>> rewirings;
auto resolve_redirection = [&](auto& redirection) -> ErrorOr<void> {
auto rewiring = TRY(redirection.apply());
auto rewiring = TRY(redirection->apply());
if (rewiring->fd_action != AST::Rewiring::Close::ImmediatelyCloseNew)
rewirings.append(*rewiring);
@ -675,18 +675,18 @@ ErrorOr<RefPtr<Job>> Shell::run_command(const AST::Command& command)
auto apply_rewirings = [&]() -> ErrorOr<void> {
for (auto& rewiring : rewirings) {
dbgln_if(SH_DEBUG, "in {}<{}>, dup2({}, {})", command.argv.is_empty() ? "(<Empty>)"sv : command.argv[0], getpid(), rewiring.old_fd, rewiring.new_fd);
int rc = dup2(rewiring.old_fd, rewiring.new_fd);
dbgln_if(SH_DEBUG, "in {}<{}>, dup2({}, {})", command.argv.is_empty() ? "(<Empty>)"sv : command.argv[0], getpid(), rewiring->old_fd, rewiring->new_fd);
int rc = dup2(rewiring->old_fd, rewiring->new_fd);
if (rc < 0)
return Error::from_syscall("dup2"sv, rc);
// {new,old}_fd is closed via the `fds` collector, but rewiring.other_pipe_end->{new,old}_fd
// {new,old}_fd is closed via the `fds` collector, but rewiring->other_pipe_end->{new,old}_fd
// isn't yet in that collector when the first child spawns.
if (rewiring.other_pipe_end) {
if (rewiring.fd_action == AST::Rewiring::Close::RefreshNew) {
if (rewiring.other_pipe_end && close(rewiring.other_pipe_end->new_fd) < 0)
if (rewiring->other_pipe_end) {
if (rewiring->fd_action == AST::Rewiring::Close::RefreshNew) {
if (rewiring->other_pipe_end && close(rewiring->other_pipe_end->new_fd) < 0)
perror("close other pipe end");
} else if (rewiring.fd_action == AST::Rewiring::Close::RefreshOld) {
if (rewiring.other_pipe_end && close(rewiring.other_pipe_end->old_fd) < 0)
} else if (rewiring->fd_action == AST::Rewiring::Close::RefreshOld) {
if (rewiring->other_pipe_end && close(rewiring->other_pipe_end->old_fd) < 0)
perror("close other pipe end");
}
}
@ -714,7 +714,7 @@ ErrorOr<RefPtr<Job>> Shell::run_command(const AST::Command& command)
SavedFileDescriptors fds { rewirings };
for (auto& rewiring : rewirings)
TRY(Core::System::dup2(rewiring.old_fd, rewiring.new_fd));
TRY(Core::System::dup2(rewiring->old_fd, rewiring->new_fd));
if (int local_return_code = 0; invoke_function(command, local_return_code)) {
last_return_code = local_return_code;
@ -1001,7 +1001,7 @@ void Shell::run_tail(RefPtr<Job> job)
}
}
NonnullRefPtrVector<Job> Shell::run_commands(Vector<AST::Command>& commands)
Vector<NonnullRefPtr<Job>> Shell::run_commands(Vector<AST::Command>& commands)
{
if (m_error != ShellError::None) {
possibly_print_error();
@ -1010,7 +1010,7 @@ NonnullRefPtrVector<Job> Shell::run_commands(Vector<AST::Command>& commands)
return {};
}
NonnullRefPtrVector<Job> spawned_jobs;
Vector<NonnullRefPtr<Job>> spawned_jobs;
for (auto& command : commands) {
if constexpr (SH_DEBUG) {
@ -1018,13 +1018,13 @@ NonnullRefPtrVector<Job> Shell::run_commands(Vector<AST::Command>& commands)
for (auto& arg : command.argv)
dbgln("argv: {}", arg);
for (auto& redir : command.redirections) {
if (redir.is_path_redirection()) {
if (redir->is_path_redirection()) {
auto path_redir = (const AST::PathRedirection*)&redir;
dbgln("redir path '{}' <-({})-> {}", path_redir->path, (int)path_redir->direction, path_redir->fd);
} else if (redir.is_fd_redirection()) {
} else if (redir->is_fd_redirection()) {
auto* fdredir = (const AST::FdRedirection*)&redir;
dbgln("redir fd {} -> {}", fdredir->old_fd, fdredir->new_fd);
} else if (redir.is_close_redirection()) {
} else if (redir->is_close_redirection()) {
auto close_redir = (const AST::CloseRedirection*)&redir;
dbgln("close fd {}", close_redir->fd);
} else {
@ -2551,7 +2551,7 @@ RefPtr<AST::Node> Shell::parse(StringView input, bool interactive, bool as_comma
auto nodes = parser.parse_as_multiple_expressions();
return make_ref_counted<AST::ListConcatenate>(
nodes.is_empty() ? AST::Position { 0, 0, { 0, 0 }, { 0, 0 } } : nodes.first().position(),
nodes.is_empty() ? AST::Position { 0, 0, { 0, 0 }, { 0, 0 } } : nodes.first()->position(),
move(nodes));
}
@ -2572,10 +2572,10 @@ void FileDescriptionCollector::add(int fd)
m_fds.append(fd);
}
SavedFileDescriptors::SavedFileDescriptors(NonnullRefPtrVector<AST::Rewiring> const& intended_rewirings)
SavedFileDescriptors::SavedFileDescriptors(Vector<NonnullRefPtr<AST::Rewiring>> const& intended_rewirings)
{
for (auto& rewiring : intended_rewirings) {
int new_fd = dup(rewiring.new_fd);
int new_fd = dup(rewiring->new_fd);
if (new_fd < 0) {
if (errno != EBADF)
perror("dup");
@ -2589,7 +2589,7 @@ SavedFileDescriptors::SavedFileDescriptors(NonnullRefPtrVector<AST::Rewiring> co
auto rc = fcntl(new_fd, F_SETFD, flags | FD_CLOEXEC);
VERIFY(rc == 0);
m_saves.append({ rewiring.new_fd, new_fd });
m_saves.append({ rewiring->new_fd, new_fd });
m_collector.add(new_fd);
}
}

View file

@ -152,11 +152,11 @@ public:
Optional<RunnablePath> runnable_path_for(StringView);
Optional<DeprecatedString> help_path_for(Vector<RunnablePath> visited, RunnablePath const& runnable_path);
ErrorOr<RefPtr<Job>> run_command(const AST::Command&);
NonnullRefPtrVector<Job> run_commands(Vector<AST::Command>&);
Vector<NonnullRefPtr<Job>> run_commands(Vector<AST::Command>&);
bool run_file(DeprecatedString const&, bool explicitly_invoked = true);
ErrorOr<bool> run_builtin(const AST::Command&, NonnullRefPtrVector<AST::Rewiring> const&, int& retval);
ErrorOr<bool> run_builtin(const AST::Command&, Vector<NonnullRefPtr<AST::Rewiring>> const&, int& retval);
bool has_builtin(StringView) const;
ErrorOr<RefPtr<AST::Node>> run_immediate_function(StringView name, AST::ImmediateExpression& invoking_node, NonnullRefPtrVector<AST::Node> const&);
ErrorOr<RefPtr<AST::Node>> run_immediate_function(StringView name, AST::ImmediateExpression& invoking_node, Vector<NonnullRefPtr<AST::Node>> const&);
static bool has_immediate_function(StringView);
void block_on_job(RefPtr<Job>);
void block_on_pipeline(RefPtr<AST::Pipeline>);
@ -423,13 +423,13 @@ private:
virtual void custom_event(Core::CustomEvent&) override;
#define __ENUMERATE_SHELL_IMMEDIATE_FUNCTION(name) \
ErrorOr<RefPtr<AST::Node>> immediate_##name(AST::ImmediateExpression& invoking_node, NonnullRefPtrVector<AST::Node> const&);
ErrorOr<RefPtr<AST::Node>> immediate_##name(AST::ImmediateExpression& invoking_node, Vector<NonnullRefPtr<AST::Node>> const&);
ENUMERATE_SHELL_IMMEDIATE_FUNCTIONS();
#undef __ENUMERATE_SHELL_IMMEDIATE_FUNCTION
ErrorOr<RefPtr<AST::Node>> immediate_length_impl(AST::ImmediateExpression& invoking_node, NonnullRefPtrVector<AST::Node> const&, bool across);
ErrorOr<RefPtr<AST::Node>> immediate_length_impl(AST::ImmediateExpression& invoking_node, Vector<NonnullRefPtr<AST::Node>> const&, bool across);
#define __ENUMERATE_SHELL_BUILTIN(builtin) \
ErrorOr<int> builtin_##builtin(Main::Arguments);
@ -460,7 +460,7 @@ private:
HashMap<DeprecatedString, ShellFunction> m_functions;
NonnullOwnPtrVector<LocalFrame> m_local_frames;
Promise::List m_active_promises;
NonnullRefPtrVector<AST::Redirection> m_global_redirections;
Vector<NonnullRefPtr<AST::Redirection>> m_global_redirections;
HashMap<DeprecatedString, DeprecatedString> m_aliases;
bool m_is_interactive { true };

View file

@ -421,7 +421,7 @@ private:
{
for (auto& entry : node->entries()) {
ScopedValueRollback first_in_command { m_is_first_in_command };
entry.visit(*this);
entry->visit(*this);
}
for (auto& position : node->separator_positions()) {