From 68b5df6bf17c55af258f44a18d0ddd41c660d38d Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 20 Feb 2023 18:26:54 +0100 Subject: [PATCH] Shell: Fix (and paper over) various const-correctness issues --- .../Shell/ShellComprehensionEngine.cpp | 4 +- Userland/Shell/AST.cpp | 60 +++++++++---------- Userland/Shell/AST.h | 54 ++++++++--------- Userland/Shell/Builtin.cpp | 10 ++-- Userland/Shell/Formatter.h | 4 +- Userland/Shell/Job.cpp | 2 +- Userland/Shell/Job.h | 2 +- Userland/Shell/Shell.cpp | 16 ++--- Userland/Shell/Shell.h | 10 ++-- 9 files changed, 81 insertions(+), 81 deletions(-) diff --git a/Userland/Libraries/LibCodeComprehension/Shell/ShellComprehensionEngine.cpp b/Userland/Libraries/LibCodeComprehension/Shell/ShellComprehensionEngine.cpp index 26230ad3b9..504343f001 100644 --- a/Userland/Libraries/LibCodeComprehension/Shell/ShellComprehensionEngine.cpp +++ b/Userland/Libraries/LibCodeComprehension/Shell/ShellComprehensionEngine.cpp @@ -180,7 +180,7 @@ Optional ShellComprehensionEngine::find_decl return {}; } - auto name = static_ptr_cast<::Shell::AST::BarewordLiteral>(result.matching_node)->text(); + auto name = static_ptr_cast<::Shell::AST::BarewordLiteral const>(result.matching_node)->text(); auto& declarations = all_declarations(); for (auto& entry : declarations) { for (auto& declaration : entry.value) { @@ -209,7 +209,7 @@ void ShellComprehensionEngine::update_declared_symbols(DocumentData const& docum DeprecatedString name; if (literal->is_bareword()) - name = static_ptr_cast<::Shell::AST::BarewordLiteral>(literal)->text(); + name = static_ptr_cast<::Shell::AST::BarewordLiteral const>(literal)->text(); if (!name.is_empty()) { dbgln("Found variable {}", name); diff --git a/Userland/Shell/AST.cpp b/Userland/Shell/AST.cpp index 3d83b30193..838b5e01f7 100644 --- a/Userland/Shell/AST.cpp +++ b/Userland/Shell/AST.cpp @@ -260,7 +260,7 @@ void Node::clear_syntax_error() m_syntax_error_node->clear_syntax_error(); } -void Node::set_is_syntax_error(SyntaxError const& error_node) +void Node::set_is_syntax_error(SyntaxError& error_node) { if (!m_syntax_error_node) { m_syntax_error_node = error_node; @@ -331,14 +331,14 @@ Node::Node(Position position) { } -Vector Node::complete_for_editor(Shell& shell, size_t offset, HitTestResult const& hit_test_result) +Vector Node::complete_for_editor(Shell& shell, size_t offset, HitTestResult const& hit_test_result) const { auto matching_node = hit_test_result.matching_node; if (matching_node) { auto kind = matching_node->kind(); StringLiteral::EnclosureType enclosure_type = StringLiteral::EnclosureType::None; if (kind == Kind::StringLiteral) - enclosure_type = static_cast(matching_node.ptr())->enclosure_type(); + enclosure_type = static_cast(matching_node.ptr())->enclosure_type(); auto set_results_trivia = [enclosure_type](Vector&& suggestions) { if (enclosure_type != StringLiteral::EnclosureType::None) { @@ -352,12 +352,12 @@ Vector Node::complete_for_editor(Shell& shell, size_ StringView text; size_t corrected_offset; if (kind == Kind::BarewordLiteral) { - auto* node = static_cast(matching_node.ptr()); + auto* node = static_cast(matching_node.ptr()); text = node->text(); escape_mode = Shell::EscapeMode::Bareword; corrected_offset = find_offset_into_node(text, offset - matching_node->position().start_offset, escape_mode); } else { - auto* node = static_cast(matching_node.ptr()); + auto* node = static_cast(matching_node.ptr()); text = node->text(); escape_mode = enclosure_type == StringLiteral::EnclosureType::SingleQuotes ? Shell::EscapeMode::SingleQuotedString : Shell::EscapeMode::DoubleQuotedString; corrected_offset = find_offset_into_node(text, offset - matching_node->position().start_offset + 1, escape_mode); @@ -382,9 +382,9 @@ Vector Node::complete_for_editor(Shell& shell, size_ DeprecatedString program_name; if (program_name_node->is_bareword()) - program_name = static_cast(program_name_node.ptr())->text(); + program_name = static_cast(program_name_node.ptr())->text(); else - program_name = static_cast(program_name_node.ptr())->text(); + program_name = static_cast(program_name_node.ptr())->text(); return set_results_trivia(shell.complete_option(program_name, text, corrected_offset, hit_test_result.closest_command_node.ptr(), hit_test_result.matching_node)); } @@ -553,7 +553,7 @@ HitTestResult ListConcatenate::hit_test_position(size_t offset) const return {}; } -RefPtr ListConcatenate::leftmost_trivial_literal() const +RefPtr ListConcatenate::leftmost_trivial_literal() const { if (m_list.is_empty()) return nullptr; @@ -764,14 +764,14 @@ HitTestResult CastToCommand::hit_test_position(size_t offset) const return result; } -Vector CastToCommand::complete_for_editor(Shell& shell, size_t offset, HitTestResult const& hit_test_result) +Vector CastToCommand::complete_for_editor(Shell& shell, size_t offset, HitTestResult const& hit_test_result) const { auto matching_node = hit_test_result.matching_node; if (!matching_node || !matching_node->is_bareword()) return {}; auto corrected_offset = offset - matching_node->position().start_offset; - auto* node = static_cast(matching_node.ptr()); + auto* node = static_cast(matching_node.ptr()); if (corrected_offset > node->text().length()) return {}; @@ -779,7 +779,7 @@ Vector CastToCommand::complete_for_editor(Shell& she return shell.complete_program_name(node->text(), corrected_offset); } -RefPtr CastToCommand::leftmost_trivial_literal() const +RefPtr CastToCommand::leftmost_trivial_literal() const { return m_inner->leftmost_trivial_literal(); } @@ -841,7 +841,7 @@ HitTestResult CastToList::hit_test_position(size_t offset) const return m_inner->hit_test_position(offset); } -RefPtr CastToList::leftmost_trivial_literal() const +RefPtr CastToList::leftmost_trivial_literal() const { return m_inner->leftmost_trivial_literal(); } @@ -1124,7 +1124,7 @@ HitTestResult FunctionDeclaration::hit_test_position(size_t offset) const return result; } -Vector FunctionDeclaration::complete_for_editor(Shell& shell, size_t offset, HitTestResult const& hit_test_result) +Vector FunctionDeclaration::complete_for_editor(Shell& shell, size_t offset, HitTestResult const& hit_test_result) const { auto matching_node = hit_test_result.matching_node; if (!matching_node) @@ -1134,7 +1134,7 @@ Vector FunctionDeclaration::complete_for_editor(Shel return matching_node->complete_for_editor(shell, offset, hit_test_result); auto corrected_offset = offset - matching_node->position().start_offset - 1; // Skip the first '$' - auto* node = static_cast(matching_node.ptr()); + auto* node = static_cast(matching_node.ptr()); auto name = node->name().substring_view(0, corrected_offset); @@ -1863,14 +1863,14 @@ HitTestResult Execute::hit_test_position(size_t offset) const return result; } -Vector Execute::complete_for_editor(Shell& shell, size_t offset, HitTestResult const& hit_test_result) +Vector Execute::complete_for_editor(Shell& shell, size_t offset, HitTestResult const& hit_test_result) const { auto matching_node = hit_test_result.matching_node; if (!matching_node || !matching_node->is_bareword()) return {}; auto corrected_offset = offset - matching_node->position().start_offset; - auto* node = static_cast(matching_node.ptr()); + auto* node = static_cast(matching_node.ptr()); if (corrected_offset > node->text().length()) return {}; @@ -2043,7 +2043,7 @@ void ImmediateExpression::highlight_in_editor(Line::Editor& editor, Shell& shell editor.stylize({ m_closing_brace_position->start_offset, m_closing_brace_position->end_offset }, { Line::Style::Foreground(Line::Style::XtermColor::Green) }); } -Vector ImmediateExpression::complete_for_editor(Shell& shell, size_t offset, HitTestResult const& hit_test_result) +Vector ImmediateExpression::complete_for_editor(Shell& shell, size_t offset, HitTestResult const& hit_test_result) const { auto matching_node = hit_test_result.matching_node; if (!matching_node || matching_node != this) @@ -2135,7 +2135,7 @@ HitTestResult Join::hit_test_position(size_t offset) const return m_right->hit_test_position(offset); } -RefPtr Join::leftmost_trivial_literal() const +RefPtr Join::leftmost_trivial_literal() const { if (auto value = m_left->leftmost_trivial_literal()) return value; @@ -2558,14 +2558,14 @@ HitTestResult PathRedirectionNode::hit_test_position(size_t offset) const return result; } -Vector PathRedirectionNode::complete_for_editor(Shell& shell, size_t offset, HitTestResult const& hit_test_result) +Vector PathRedirectionNode::complete_for_editor(Shell& shell, size_t offset, HitTestResult const& hit_test_result) const { auto matching_node = hit_test_result.matching_node; if (!matching_node || !matching_node->is_bareword()) return {}; auto corrected_offset = offset - matching_node->position().start_offset; - auto* node = static_cast(matching_node.ptr()); + auto* node = static_cast(matching_node.ptr()); if (corrected_offset > node->text().length()) return {}; @@ -2810,7 +2810,7 @@ HitTestResult Sequence::hit_test_position(size_t offset) const return {}; } -RefPtr Sequence::leftmost_trivial_literal() const +RefPtr Sequence::leftmost_trivial_literal() const { for (auto& entry : m_entries) { if (auto node = entry.leftmost_trivial_literal()) @@ -2899,7 +2899,7 @@ HitTestResult Slice::hit_test_position(size_t offset) const return m_selector->hit_test_position(offset); } -Vector Slice::complete_for_editor(Shell& shell, size_t offset, HitTestResult const& hit_test_result) +Vector Slice::complete_for_editor(Shell& shell, size_t offset, HitTestResult const& hit_test_result) const { // TODO: Maybe intercept this, and suggest values in range? return m_selector->complete_for_editor(shell, offset, hit_test_result); @@ -2958,7 +2958,7 @@ HitTestResult SimpleVariable::hit_test_position(size_t offset) const return { this, this, nullptr }; } -Vector SimpleVariable::complete_for_editor(Shell& shell, size_t offset, HitTestResult const& hit_test_result) +Vector SimpleVariable::complete_for_editor(Shell& shell, size_t offset, HitTestResult const& hit_test_result) const { auto matching_node = hit_test_result.matching_node; if (!matching_node) @@ -3012,7 +3012,7 @@ void SpecialVariable::highlight_in_editor(Line::Editor& editor, Shell& shell, Hi m_slice->highlight_in_editor(editor, shell, metadata); } -Vector SpecialVariable::complete_for_editor(Shell&, size_t, HitTestResult const&) +Vector SpecialVariable::complete_for_editor(Shell&, size_t, HitTestResult const&) const { return {}; } @@ -3134,7 +3134,7 @@ void Juxtaposition::highlight_in_editor(Line::Editor& editor, Shell& shell, High } } -Vector Juxtaposition::complete_for_editor(Shell& shell, size_t offset, HitTestResult const& hit_test_result) +Vector Juxtaposition::complete_for_editor(Shell& shell, size_t offset, HitTestResult const& hit_test_result) const { auto matching_node = hit_test_result.matching_node; if (m_left->would_execute() || m_right->would_execute()) { @@ -3312,7 +3312,7 @@ SyntaxError::SyntaxError(Position position, DeprecatedString error, bool is_cont { } -SyntaxError const& SyntaxError::syntax_error_node() const +SyntaxError& SyntaxError::syntax_error_node() { return *this; } @@ -3364,7 +3364,7 @@ HitTestResult Tilde::hit_test_position(size_t offset) const return { this, this, nullptr }; } -Vector Tilde::complete_for_editor(Shell& shell, size_t offset, HitTestResult const& hit_test_result) +Vector Tilde::complete_for_editor(Shell& shell, size_t offset, HitTestResult const& hit_test_result) const { auto matching_node = hit_test_result.matching_node; if (!matching_node) @@ -3718,7 +3718,7 @@ NonnullRefPtr SimpleVariableValue::resolve_without_cast(RefPtr she if (!m_slices.is_empty()) result = result->with_slices(m_slices); - return result; + return const_cast(*result); } return *this; @@ -3755,12 +3755,12 @@ Vector SpecialVariableValue::resolve_as_list(RefPtr she return { resolve_slices(shell, DeprecatedString::number(getpid()), m_slices) }; case '*': if (auto argv = shell->lookup_local_variable("ARGV"sv)) - return resolve_slices(shell, argv->resolve_as_list(shell), m_slices); + return resolve_slices(shell, const_cast(*argv).resolve_as_list(shell), m_slices); return resolve_slices(shell, Vector {}, m_slices); case '#': if (auto argv = shell->lookup_local_variable("ARGV"sv)) { if (argv->is_list()) { - auto list_argv = static_cast(argv.ptr()); + auto list_argv = static_cast(argv.ptr()); return { resolve_slices(shell, DeprecatedString::number(list_argv->values().size()), m_slices) }; } return { resolve_slices(shell, "1", m_slices) }; diff --git a/Userland/Shell/AST.h b/Userland/Shell/AST.h index 0f1c293ffd..4d68c7848a 100644 --- a/Userland/Shell/AST.h +++ b/Userland/Shell/AST.h @@ -220,9 +220,9 @@ struct Command { }; struct HitTestResult { - RefPtr matching_node; - RefPtr closest_node_with_semantic_meaning; // This is used if matching_node is a bareword - RefPtr closest_command_node; // This is used if matching_node is a bareword, and it is not the first in a list + RefPtr matching_node; + RefPtr closest_node_with_semantic_meaning; // This is used if matching_node is a bareword + RefPtr closest_command_node; // This is used if matching_node is a bareword, and it is not the first in a list }; class Value : public RefCounted { @@ -424,7 +424,7 @@ public: virtual void for_each_entry(RefPtr shell, Function)> callback); virtual RefPtr run(RefPtr) = 0; virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) = 0; - virtual Vector complete_for_editor(Shell&, size_t, HitTestResult const&); + virtual Vector complete_for_editor(Shell&, size_t, HitTestResult const&) const; Vector complete_for_editor(Shell& shell, size_t offset); virtual HitTestResult hit_test_position(size_t offset) const { @@ -451,14 +451,14 @@ public: Position const& position() const { return m_position; } virtual void clear_syntax_error(); - virtual void set_is_syntax_error(SyntaxError const& error_node); - virtual SyntaxError const& syntax_error_node() const + virtual void set_is_syntax_error(SyntaxError& error_node); + virtual SyntaxError& syntax_error_node() { VERIFY(is_syntax_error()); return *m_syntax_error_node; } - virtual RefPtr leftmost_trivial_literal() const { return nullptr; } + virtual RefPtr leftmost_trivial_literal() const { return nullptr; } Vector to_lazy_evaluated_commands(RefPtr shell); @@ -534,7 +534,7 @@ public: PathRedirectionNode(Position, int, NonnullRefPtr); virtual ~PathRedirectionNode(); virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override; - virtual Vector complete_for_editor(Shell&, size_t, HitTestResult const&) override; + virtual Vector complete_for_editor(Shell&, size_t, HitTestResult const&) const override; virtual HitTestResult hit_test_position(size_t offset) const override; virtual bool is_command() const override { return true; } virtual bool is_list() const override { return true; } @@ -585,7 +585,7 @@ private: virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override; virtual HitTestResult hit_test_position(size_t) const override; virtual bool is_list() const override { return true; } - virtual RefPtr leftmost_trivial_literal() const override; + virtual RefPtr leftmost_trivial_literal() const override; Vector> m_list; }; @@ -622,7 +622,7 @@ private: virtual RefPtr run(RefPtr) override; virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override; virtual bool is_bareword() const override { return true; } - virtual RefPtr leftmost_trivial_literal() const override { return this; } + virtual RefPtr leftmost_trivial_literal() const override { return this; } DeprecatedString m_text; }; @@ -659,10 +659,10 @@ private: virtual RefPtr run(RefPtr) override; virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override; virtual HitTestResult hit_test_position(size_t) const override; - virtual Vector complete_for_editor(Shell&, size_t, HitTestResult const&) override; + virtual Vector complete_for_editor(Shell&, size_t, HitTestResult const&) const override; virtual bool is_command() const override { return true; } virtual bool is_list() const override { return true; } - virtual RefPtr leftmost_trivial_literal() const override; + virtual RefPtr leftmost_trivial_literal() const override; NonnullRefPtr m_inner; }; @@ -683,7 +683,7 @@ private: virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override; virtual HitTestResult hit_test_position(size_t) const override; virtual bool is_list() const override { return true; } - virtual RefPtr leftmost_trivial_literal() const override; + virtual RefPtr leftmost_trivial_literal() const override; RefPtr m_inner; }; @@ -849,7 +849,7 @@ private: virtual RefPtr run(RefPtr) override; virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override; virtual HitTestResult hit_test_position(size_t) const override; - virtual Vector complete_for_editor(Shell&, size_t, HitTestResult const&) override; + virtual Vector complete_for_editor(Shell&, size_t, HitTestResult const&) const override; virtual bool would_execute() const override { return true; } virtual bool should_override_execution_in_current_process() const override { return true; } @@ -982,7 +982,7 @@ private: virtual RefPtr run(RefPtr) override; virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override; virtual HitTestResult hit_test_position(size_t) const override; - virtual Vector complete_for_editor(Shell&, size_t, HitTestResult const&) override; + virtual Vector complete_for_editor(Shell&, size_t, HitTestResult const&) const override; virtual bool is_execute() const override { return true; } virtual bool would_execute() const override { return true; } @@ -1034,7 +1034,7 @@ private: virtual void dump(int level) const override; virtual RefPtr run(RefPtr) override; virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override; - Vector complete_for_editor(Shell&, size_t, HitTestResult const&) override; + virtual Vector complete_for_editor(Shell&, size_t, HitTestResult const&) const override; virtual HitTestResult hit_test_position(size_t) const override; NonnullRefPtrVector m_arguments; @@ -1059,7 +1059,7 @@ private: virtual HitTestResult hit_test_position(size_t) const override; virtual bool is_command() const override { return true; } virtual bool is_list() const override { return true; } - virtual RefPtr leftmost_trivial_literal() const override; + virtual RefPtr leftmost_trivial_literal() const override; NonnullRefPtr m_left; NonnullRefPtr m_right; @@ -1204,7 +1204,7 @@ private: virtual HitTestResult hit_test_position(size_t) const override; virtual bool is_list() const override { return true; } virtual bool should_override_execution_in_current_process() const override { return true; } - virtual RefPtr leftmost_trivial_literal() const override; + virtual RefPtr leftmost_trivial_literal() const override; NonnullRefPtrVector m_entries; Vector m_separator_positions; @@ -1242,7 +1242,7 @@ public: virtual void dump(int level) const override; virtual RefPtr run(RefPtr) override; virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override; - virtual Vector complete_for_editor(Shell&, size_t, HitTestResult const&) override; + virtual Vector complete_for_editor(Shell&, size_t, HitTestResult const&) const override; virtual HitTestResult hit_test_position(size_t) const override; protected: @@ -1284,7 +1284,7 @@ private: virtual void dump(int level) const override; virtual RefPtr run(RefPtr) override; virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override; - virtual Vector complete_for_editor(Shell&, size_t, HitTestResult const&) override; + virtual Vector complete_for_editor(Shell&, size_t, HitTestResult const&) const override; virtual HitTestResult hit_test_position(size_t) const override; virtual bool is_simple_variable() const override { return true; } @@ -1304,7 +1304,7 @@ private: virtual void dump(int level) const override; virtual RefPtr run(RefPtr) override; virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override; - virtual Vector complete_for_editor(Shell&, size_t, HitTestResult const&) override; + virtual Vector complete_for_editor(Shell&, size_t, HitTestResult const&) const override; virtual HitTestResult hit_test_position(size_t) const override; char m_name { 0 }; @@ -1329,7 +1329,7 @@ private: virtual RefPtr run(RefPtr) override; virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override; virtual HitTestResult hit_test_position(size_t) const override; - virtual Vector complete_for_editor(Shell&, size_t, HitTestResult const&) override; + virtual Vector complete_for_editor(Shell&, size_t, HitTestResult const&) const override; NonnullRefPtr m_left; NonnullRefPtr m_right; @@ -1363,7 +1363,7 @@ private: virtual RefPtr run(RefPtr) override; virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override; virtual HitTestResult hit_test_position(size_t) const override; - virtual RefPtr leftmost_trivial_literal() const override { return this; }; + virtual RefPtr leftmost_trivial_literal() const override { return this; }; DeprecatedString m_end; bool m_allows_interpolation { false }; @@ -1392,7 +1392,7 @@ private: virtual void dump(int level) const override; virtual RefPtr run(RefPtr) override; virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override; - virtual RefPtr leftmost_trivial_literal() const override { return this; }; + virtual RefPtr leftmost_trivial_literal() const override { return this; }; DeprecatedString m_text; EnclosureType m_enclosure_type; @@ -1431,7 +1431,7 @@ public: { m_is_cleared = true; } - virtual void set_is_syntax_error(SyntaxError const& error) override + virtual void set_is_syntax_error(SyntaxError& error) override { m_position = error.position(); m_is_cleared = error.m_is_cleared; @@ -1447,7 +1447,7 @@ private: virtual RefPtr run(RefPtr) override; virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override; virtual HitTestResult hit_test_position(size_t) const override { return { nullptr, nullptr, nullptr }; } - virtual SyntaxError const& syntax_error_node() const override; + virtual SyntaxError& syntax_error_node() override; DeprecatedString m_syntax_error_text; bool m_is_continuable { false }; @@ -1484,7 +1484,7 @@ private: virtual void dump(int level) const override; virtual RefPtr run(RefPtr) override; virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override; - virtual Vector complete_for_editor(Shell&, size_t, HitTestResult const&) override; + virtual Vector complete_for_editor(Shell&, size_t, HitTestResult const&) const override; virtual HitTestResult hit_test_position(size_t) const override; virtual bool is_tilde() const override { return true; } diff --git a/Userland/Shell/Builtin.cpp b/Userland/Shell/Builtin.cpp index ad9c03c7a0..a4e78b8604 100644 --- a/Userland/Shell/Builtin.cpp +++ b/Userland/Shell/Builtin.cpp @@ -554,7 +554,7 @@ int Shell::builtin_export(int argc, char const** argv) if (parts.size() == 1) { auto value = lookup_local_variable(parts[0]); if (value) { - auto values = value->resolve_as_list(*this); + auto values = const_cast(*value).resolve_as_list(*this); StringBuilder builder; builder.join(' ', values); parts.append(builder.to_deprecated_string()); @@ -946,9 +946,9 @@ int Shell::builtin_shift(int argc, char const** argv) } if (!argv_->is_list()) - argv_ = adopt_ref(*new AST::ListValue({ argv_.release_nonnull() })); + argv_ = adopt_ref(*new AST::ListValue({ const_cast(*argv_) })); - auto& values = static_cast(argv_.ptr())->values(); + auto& values = const_cast(static_cast(argv_.ptr()))->values(); if ((size_t)count > values.size()) { warnln("shift: shift count must not be greater than {}", values.size()); return 1; @@ -975,7 +975,7 @@ int Shell::builtin_source(int argc, char const** argv) auto previous_argv = lookup_local_variable("ARGV"sv); ScopeGuard guard { [&] { if (!args.is_empty()) - set_local_variable("ARGV", move(previous_argv)); + set_local_variable("ARGV", const_cast(*previous_argv)); } }; if (!args.is_empty()) @@ -1337,7 +1337,7 @@ int Shell::builtin_argsparser_parse(int argc, char const** argv) auto enlist = [&](auto name, auto value) -> NonnullRefPtr { auto variable = lookup_local_variable(name); if (variable) { - auto list = variable->resolve_as_list(*this); + auto list = const_cast(*variable).resolve_as_list(*this); auto new_value = value->resolve_as_string(*this); list.append(move(new_value)); return make_ref_counted(move(list)); diff --git a/Userland/Shell/Formatter.h b/Userland/Shell/Formatter.h index b1f2cb4059..ac58e54ec2 100644 --- a/Userland/Shell/Formatter.h +++ b/Userland/Shell/Formatter.h @@ -117,8 +117,8 @@ private: StringView m_source; size_t m_output_cursor { 0 }; ssize_t m_cursor { -1 }; - RefPtr m_root_node; - AST::Node* m_hit_node { nullptr }; + RefPtr m_root_node; + AST::Node const* m_hit_node { nullptr }; const AST::Node* m_parent_node { nullptr }; const AST::Node* m_last_visited_node { nullptr }; diff --git a/Userland/Shell/Job.cpp b/Userland/Shell/Job.cpp index 171018b8ec..919b0593a8 100644 --- a/Userland/Shell/Job.cpp +++ b/Userland/Shell/Job.cpp @@ -96,7 +96,7 @@ void Job::set_signalled(int sig) on_exit(*this); } -void Job::unblock() const +void Job::unblock() { if (!m_exited && on_exit) on_exit(*this); diff --git a/Userland/Shell/Job.h b/Userland/Shell/Job.h index 6f214f1fb4..f6cef51bba 100644 --- a/Userland/Shell/Job.h +++ b/Userland/Shell/Job.h @@ -63,7 +63,7 @@ public: bool should_announce_signal() const { return m_should_announce_signal; } bool is_suspended() const { return m_is_suspended; } bool shell_did_continue() const { return m_shell_did_continue; } - void unblock() const; + void unblock(); Core::ElapsedTimer& timer() { return m_command_timer; } diff --git a/Userland/Shell/Shell.cpp b/Userland/Shell/Shell.cpp index 2a2512427a..ef1e94ac93 100644 --- a/Userland/Shell/Shell.cpp +++ b/Userland/Shell/Shell.cpp @@ -350,7 +350,7 @@ Shell::LocalFrame* Shell::find_frame_containing_local_variable(StringView name) return nullptr; } -RefPtr Shell::lookup_local_variable(StringView name) const +RefPtr Shell::lookup_local_variable(StringView name) const { if (auto* frame = find_frame_containing_local_variable(name)) return frame->local_variables.get(name).value(); @@ -361,7 +361,7 @@ RefPtr Shell::lookup_local_variable(StringView name) const return nullptr; } -RefPtr Shell::get_argument(size_t index) const +RefPtr Shell::get_argument(size_t index) const { if (index == 0) return adopt_ref(*new AST::StringValue(current_script)); @@ -369,7 +369,7 @@ RefPtr Shell::get_argument(size_t index) const --index; if (auto argv = lookup_local_variable("ARGV"sv)) { if (argv->is_list_without_resolution()) { - AST::ListValue* list = static_cast(argv.ptr()); + AST::ListValue const* list = static_cast(argv.ptr()); if (list->values().size() <= index) return nullptr; @@ -390,7 +390,7 @@ DeprecatedString Shell::local_variable_or(StringView name, DeprecatedString cons auto value = lookup_local_variable(name); if (value) { StringBuilder builder; - builder.join(' ', value->resolve_as_list(*this)); + builder.join(' ', const_cast(*value).resolve_as_list(const_cast(*this))); return builder.to_deprecated_string(); } return replacement; @@ -1068,7 +1068,7 @@ bool Shell::is_allowed_to_modify_termios(const AST::Command& command) const if (!value) return false; - return value->resolve_as_list(*this).contains_slow(command.argv[0]); + return const_cast(*value).resolve_as_list(const_cast(*this)).contains_slow(command.argv[0]); } void Shell::restore_ios() @@ -1093,7 +1093,7 @@ void Shell::block_on_pipeline(RefPtr pipeline) void Shell::block_on_job(RefPtr job) { - TemporaryChange current_job { m_current_job, job.ptr() }; + TemporaryChange current_job { m_current_job, job.ptr() }; if (!job) return; @@ -1671,7 +1671,7 @@ ErrorOr> Shell::complete_via_program_itself(s if (!node) return Error::from_string_literal("Cannot complete"); - program_name_storage = node->run(*this)->resolve_as_string(*this); + program_name_storage = const_cast(*node).run(*this)->resolve_as_string(*this); known_program_name = program_name_storage; } @@ -2281,7 +2281,7 @@ u64 Shell::find_last_job_id() const return job_id; } -Job const* Shell::find_job(u64 id, bool is_pid) +Job* Shell::find_job(u64 id, bool is_pid) { for (auto& entry : jobs) { if (is_pid) { diff --git a/Userland/Shell/Shell.h b/Userland/Shell/Shell.h index b1ea789419..f2912bcaa1 100644 --- a/Userland/Shell/Shell.h +++ b/Userland/Shell/Shell.h @@ -170,8 +170,8 @@ public: static bool has_history_event(StringView); - RefPtr get_argument(size_t) const; - RefPtr lookup_local_variable(StringView) const; + RefPtr get_argument(size_t) const; + RefPtr lookup_local_variable(StringView) const; DeprecatedString local_variable_or(StringView, DeprecatedString const&) const; void set_local_variable(DeprecatedString const&, RefPtr, bool only_in_current_frame = false); void unset_local_variable(StringView, bool only_in_current_frame = false); @@ -290,8 +290,8 @@ public: void restore_ios(); u64 find_last_job_id() const; - Job const* find_job(u64 id, bool is_pid = false); - Job const* current_job() const { return m_current_job; } + Job* find_job(u64 id, bool is_pid = false); + Job* current_job() const { return m_current_job; } void kill_job(Job const*, int sig); DeprecatedString get_history_path(); @@ -406,7 +406,7 @@ private: void add_entry_to_cache(RunnablePath const&); void remove_entry_from_cache(StringView); void stop_all_jobs(); - Job const* m_current_job { nullptr }; + Job* m_current_job { nullptr }; LocalFrame* find_frame_containing_local_variable(StringView name); LocalFrame const* find_frame_containing_local_variable(StringView name) const {