mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 18:42:43 +00:00 
			
		
		
		
	Shell: Fix (and paper over) various const-correctness issues
This commit is contained in:
		
							parent
							
								
									39a1702c99
								
							
						
					
					
						commit
						68b5df6bf1
					
				
					 9 changed files with 81 additions and 81 deletions
				
			
		|  | @ -180,7 +180,7 @@ Optional<CodeComprehension::ProjectLocation> 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); | ||||
|  |  | |||
|  | @ -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<Line::CompletionSuggestion> Node::complete_for_editor(Shell& shell, size_t offset, HitTestResult const& hit_test_result) | ||||
| Vector<Line::CompletionSuggestion> 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<StringLiteral*>(matching_node.ptr())->enclosure_type(); | ||||
|             enclosure_type = static_cast<StringLiteral const*>(matching_node.ptr())->enclosure_type(); | ||||
| 
 | ||||
|         auto set_results_trivia = [enclosure_type](Vector<Line::CompletionSuggestion>&& suggestions) { | ||||
|             if (enclosure_type != StringLiteral::EnclosureType::None) { | ||||
|  | @ -352,12 +352,12 @@ Vector<Line::CompletionSuggestion> Node::complete_for_editor(Shell& shell, size_ | |||
|             StringView text; | ||||
|             size_t corrected_offset; | ||||
|             if (kind == Kind::BarewordLiteral) { | ||||
|                 auto* node = static_cast<BarewordLiteral*>(matching_node.ptr()); | ||||
|                 auto* node = static_cast<BarewordLiteral const*>(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<StringLiteral*>(matching_node.ptr()); | ||||
|                 auto* node = static_cast<StringLiteral const*>(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<Line::CompletionSuggestion> Node::complete_for_editor(Shell& shell, size_ | |||
| 
 | ||||
|             DeprecatedString program_name; | ||||
|             if (program_name_node->is_bareword()) | ||||
|                 program_name = static_cast<BarewordLiteral*>(program_name_node.ptr())->text(); | ||||
|                 program_name = static_cast<BarewordLiteral const*>(program_name_node.ptr())->text(); | ||||
|             else | ||||
|                 program_name = static_cast<StringLiteral*>(program_name_node.ptr())->text(); | ||||
|                 program_name = static_cast<StringLiteral const*>(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<Node> ListConcatenate::leftmost_trivial_literal() const | ||||
| RefPtr<Node const> 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<Line::CompletionSuggestion> CastToCommand::complete_for_editor(Shell& shell, size_t offset, HitTestResult const& hit_test_result) | ||||
| Vector<Line::CompletionSuggestion> 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<BarewordLiteral*>(matching_node.ptr()); | ||||
|     auto* node = static_cast<BarewordLiteral const*>(matching_node.ptr()); | ||||
| 
 | ||||
|     if (corrected_offset > node->text().length()) | ||||
|         return {}; | ||||
|  | @ -779,7 +779,7 @@ Vector<Line::CompletionSuggestion> CastToCommand::complete_for_editor(Shell& she | |||
|     return shell.complete_program_name(node->text(), corrected_offset); | ||||
| } | ||||
| 
 | ||||
| RefPtr<Node> CastToCommand::leftmost_trivial_literal() const | ||||
| RefPtr<Node const> 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<Node> CastToList::leftmost_trivial_literal() const | ||||
| RefPtr<Node const> 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<Line::CompletionSuggestion> FunctionDeclaration::complete_for_editor(Shell& shell, size_t offset, HitTestResult const& hit_test_result) | ||||
| Vector<Line::CompletionSuggestion> 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<Line::CompletionSuggestion> 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<SimpleVariable*>(matching_node.ptr()); | ||||
|     auto* node = static_cast<SimpleVariable const*>(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<Line::CompletionSuggestion> Execute::complete_for_editor(Shell& shell, size_t offset, HitTestResult const& hit_test_result) | ||||
| Vector<Line::CompletionSuggestion> 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<BarewordLiteral*>(matching_node.ptr()); | ||||
|     auto* node = static_cast<BarewordLiteral const*>(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<Line::CompletionSuggestion> ImmediateExpression::complete_for_editor(Shell& shell, size_t offset, HitTestResult const& hit_test_result) | ||||
| Vector<Line::CompletionSuggestion> 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<Node> Join::leftmost_trivial_literal() const | ||||
| RefPtr<Node const> 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<Line::CompletionSuggestion> PathRedirectionNode::complete_for_editor(Shell& shell, size_t offset, HitTestResult const& hit_test_result) | ||||
| Vector<Line::CompletionSuggestion> 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<BarewordLiteral*>(matching_node.ptr()); | ||||
|     auto* node = static_cast<BarewordLiteral const*>(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<Node> Sequence::leftmost_trivial_literal() const | ||||
| RefPtr<Node const> 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<Line::CompletionSuggestion> Slice::complete_for_editor(Shell& shell, size_t offset, HitTestResult const& hit_test_result) | ||||
| Vector<Line::CompletionSuggestion> 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<Line::CompletionSuggestion> SimpleVariable::complete_for_editor(Shell& shell, size_t offset, HitTestResult const& hit_test_result) | ||||
| Vector<Line::CompletionSuggestion> 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<Line::CompletionSuggestion> SpecialVariable::complete_for_editor(Shell&, size_t, HitTestResult const&) | ||||
| Vector<Line::CompletionSuggestion> 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<Line::CompletionSuggestion> Juxtaposition::complete_for_editor(Shell& shell, size_t offset, HitTestResult const& hit_test_result) | ||||
| Vector<Line::CompletionSuggestion> 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<Line::CompletionSuggestion> Tilde::complete_for_editor(Shell& shell, size_t offset, HitTestResult const& hit_test_result) | ||||
| Vector<Line::CompletionSuggestion> 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<Value> SimpleVariableValue::resolve_without_cast(RefPtr<Shell> she | |||
|         if (!m_slices.is_empty()) | ||||
|             result = result->with_slices(m_slices); | ||||
| 
 | ||||
|         return result; | ||||
|         return const_cast<Value&>(*result); | ||||
|     } | ||||
| 
 | ||||
|     return *this; | ||||
|  | @ -3755,12 +3755,12 @@ Vector<DeprecatedString> SpecialVariableValue::resolve_as_list(RefPtr<Shell> 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<Value&>(*argv).resolve_as_list(shell), m_slices); | ||||
|         return resolve_slices(shell, Vector<DeprecatedString> {}, m_slices); | ||||
|     case '#': | ||||
|         if (auto argv = shell->lookup_local_variable("ARGV"sv)) { | ||||
|             if (argv->is_list()) { | ||||
|                 auto list_argv = static_cast<AST::ListValue*>(argv.ptr()); | ||||
|                 auto list_argv = static_cast<AST::ListValue const*>(argv.ptr()); | ||||
|                 return { resolve_slices(shell, DeprecatedString::number(list_argv->values().size()), m_slices) }; | ||||
|             } | ||||
|             return { resolve_slices(shell, "1", m_slices) }; | ||||
|  |  | |||
|  | @ -220,9 +220,9 @@ struct Command { | |||
| }; | ||||
| 
 | ||||
| struct HitTestResult { | ||||
|     RefPtr<Node> matching_node; | ||||
|     RefPtr<Node> closest_node_with_semantic_meaning; // This is used if matching_node is a bareword
 | ||||
|     RefPtr<Node> closest_command_node;               // This is used if matching_node is a bareword, and it is not the first in a list
 | ||||
|     RefPtr<Node const> matching_node; | ||||
|     RefPtr<Node const> closest_node_with_semantic_meaning; // This is used if matching_node is a bareword
 | ||||
|     RefPtr<Node const> 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<Value> { | ||||
|  | @ -424,7 +424,7 @@ public: | |||
|     virtual void for_each_entry(RefPtr<Shell> shell, Function<IterationDecision(NonnullRefPtr<Value>)> callback); | ||||
|     virtual RefPtr<Value> run(RefPtr<Shell>) = 0; | ||||
|     virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) = 0; | ||||
|     virtual Vector<Line::CompletionSuggestion> complete_for_editor(Shell&, size_t, HitTestResult const&); | ||||
|     virtual Vector<Line::CompletionSuggestion> complete_for_editor(Shell&, size_t, HitTestResult const&) const; | ||||
|     Vector<Line::CompletionSuggestion> 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<Node> leftmost_trivial_literal() const { return nullptr; } | ||||
|     virtual RefPtr<Node const> leftmost_trivial_literal() const { return nullptr; } | ||||
| 
 | ||||
|     Vector<Command> to_lazy_evaluated_commands(RefPtr<Shell> shell); | ||||
| 
 | ||||
|  | @ -534,7 +534,7 @@ public: | |||
|     PathRedirectionNode(Position, int, NonnullRefPtr<Node>); | ||||
|     virtual ~PathRedirectionNode(); | ||||
|     virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override; | ||||
|     virtual Vector<Line::CompletionSuggestion> complete_for_editor(Shell&, size_t, HitTestResult const&) override; | ||||
|     virtual Vector<Line::CompletionSuggestion> 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<Node> leftmost_trivial_literal() const override; | ||||
|     virtual RefPtr<Node const> leftmost_trivial_literal() const override; | ||||
| 
 | ||||
|     Vector<NonnullRefPtr<Node>> m_list; | ||||
| }; | ||||
|  | @ -622,7 +622,7 @@ private: | |||
|     virtual RefPtr<Value> run(RefPtr<Shell>) override; | ||||
|     virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override; | ||||
|     virtual bool is_bareword() const override { return true; } | ||||
|     virtual RefPtr<Node> leftmost_trivial_literal() const override { return this; } | ||||
|     virtual RefPtr<Node const> leftmost_trivial_literal() const override { return this; } | ||||
| 
 | ||||
|     DeprecatedString m_text; | ||||
| }; | ||||
|  | @ -659,10 +659,10 @@ private: | |||
|     virtual RefPtr<Value> run(RefPtr<Shell>) override; | ||||
|     virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override; | ||||
|     virtual HitTestResult hit_test_position(size_t) const override; | ||||
|     virtual Vector<Line::CompletionSuggestion> complete_for_editor(Shell&, size_t, HitTestResult const&) override; | ||||
|     virtual Vector<Line::CompletionSuggestion> 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<Node> leftmost_trivial_literal() const override; | ||||
|     virtual RefPtr<Node const> leftmost_trivial_literal() const override; | ||||
| 
 | ||||
|     NonnullRefPtr<Node> 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<Node> leftmost_trivial_literal() const override; | ||||
|     virtual RefPtr<Node const> leftmost_trivial_literal() const override; | ||||
| 
 | ||||
|     RefPtr<Node> m_inner; | ||||
| }; | ||||
|  | @ -849,7 +849,7 @@ private: | |||
|     virtual RefPtr<Value> run(RefPtr<Shell>) override; | ||||
|     virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override; | ||||
|     virtual HitTestResult hit_test_position(size_t) const override; | ||||
|     virtual Vector<Line::CompletionSuggestion> complete_for_editor(Shell&, size_t, HitTestResult const&) override; | ||||
|     virtual Vector<Line::CompletionSuggestion> 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<Value> run(RefPtr<Shell>) override; | ||||
|     virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override; | ||||
|     virtual HitTestResult hit_test_position(size_t) const override; | ||||
|     virtual Vector<Line::CompletionSuggestion> complete_for_editor(Shell&, size_t, HitTestResult const&) override; | ||||
|     virtual Vector<Line::CompletionSuggestion> 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<Value> run(RefPtr<Shell>) override; | ||||
|     virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override; | ||||
|     Vector<Line::CompletionSuggestion> complete_for_editor(Shell&, size_t, HitTestResult const&) override; | ||||
|     virtual 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; | ||||
|  | @ -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<Node> leftmost_trivial_literal() const override; | ||||
|     virtual RefPtr<Node const> leftmost_trivial_literal() const override; | ||||
| 
 | ||||
|     NonnullRefPtr<Node> m_left; | ||||
|     NonnullRefPtr<Node> 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<Node> leftmost_trivial_literal() const override; | ||||
|     virtual RefPtr<Node const> leftmost_trivial_literal() const override; | ||||
| 
 | ||||
|     NonnullRefPtrVector<Node> m_entries; | ||||
|     Vector<Position> m_separator_positions; | ||||
|  | @ -1242,7 +1242,7 @@ public: | |||
|     virtual void dump(int level) const override; | ||||
|     virtual RefPtr<Value> run(RefPtr<Shell>) override; | ||||
|     virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override; | ||||
|     virtual Vector<Line::CompletionSuggestion> complete_for_editor(Shell&, size_t, HitTestResult const&) override; | ||||
|     virtual Vector<Line::CompletionSuggestion> 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<Value> run(RefPtr<Shell>) override; | ||||
|     virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override; | ||||
|     virtual Vector<Line::CompletionSuggestion> complete_for_editor(Shell&, size_t, HitTestResult const&) override; | ||||
|     virtual Vector<Line::CompletionSuggestion> 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<Value> run(RefPtr<Shell>) override; | ||||
|     virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override; | ||||
|     virtual Vector<Line::CompletionSuggestion> complete_for_editor(Shell&, size_t, HitTestResult const&) override; | ||||
|     virtual Vector<Line::CompletionSuggestion> 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<Value> run(RefPtr<Shell>) override; | ||||
|     virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override; | ||||
|     virtual HitTestResult hit_test_position(size_t) const override; | ||||
|     virtual Vector<Line::CompletionSuggestion> complete_for_editor(Shell&, size_t, HitTestResult const&) override; | ||||
|     virtual Vector<Line::CompletionSuggestion> complete_for_editor(Shell&, size_t, HitTestResult const&) const override; | ||||
| 
 | ||||
|     NonnullRefPtr<Node> m_left; | ||||
|     NonnullRefPtr<Node> m_right; | ||||
|  | @ -1363,7 +1363,7 @@ private: | |||
|     virtual RefPtr<Value> run(RefPtr<Shell>) override; | ||||
|     virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override; | ||||
|     virtual HitTestResult hit_test_position(size_t) const override; | ||||
|     virtual RefPtr<Node> leftmost_trivial_literal() const override { return this; }; | ||||
|     virtual RefPtr<Node const> 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<Value> run(RefPtr<Shell>) override; | ||||
|     virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override; | ||||
|     virtual RefPtr<Node> leftmost_trivial_literal() const override { return this; }; | ||||
|     virtual RefPtr<Node const> 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<Value> run(RefPtr<Shell>) 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<Value> run(RefPtr<Shell>) override; | ||||
|     virtual void highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata = {}) override; | ||||
|     virtual Vector<Line::CompletionSuggestion> complete_for_editor(Shell&, size_t, HitTestResult const&) override; | ||||
|     virtual Vector<Line::CompletionSuggestion> 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; } | ||||
| 
 | ||||
|  |  | |||
|  | @ -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<AST::Value&>(*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<AST::Value&>(*argv_) })); | ||||
| 
 | ||||
|     auto& values = static_cast<AST::ListValue*>(argv_.ptr())->values(); | ||||
|     auto& values = const_cast<AST::ListValue*>(static_cast<AST::ListValue const*>(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<AST::Value&>(*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<AST::Value> { | ||||
|         auto variable = lookup_local_variable(name); | ||||
|         if (variable) { | ||||
|             auto list = variable->resolve_as_list(*this); | ||||
|             auto list = const_cast<AST::Value&>(*variable).resolve_as_list(*this); | ||||
|             auto new_value = value->resolve_as_string(*this); | ||||
|             list.append(move(new_value)); | ||||
|             return make_ref_counted<AST::ListValue>(move(list)); | ||||
|  |  | |||
|  | @ -117,8 +117,8 @@ private: | |||
|     StringView m_source; | ||||
|     size_t m_output_cursor { 0 }; | ||||
|     ssize_t m_cursor { -1 }; | ||||
|     RefPtr<AST::Node> m_root_node; | ||||
|     AST::Node* m_hit_node { nullptr }; | ||||
|     RefPtr<AST::Node const> 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 }; | ||||
|  |  | |||
|  | @ -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); | ||||
|  |  | |||
|  | @ -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; } | ||||
| 
 | ||||
|  |  | |||
|  | @ -350,7 +350,7 @@ Shell::LocalFrame* Shell::find_frame_containing_local_variable(StringView name) | |||
|     return nullptr; | ||||
| } | ||||
| 
 | ||||
| RefPtr<AST::Value> Shell::lookup_local_variable(StringView name) const | ||||
| RefPtr<AST::Value const> 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<AST::Value> Shell::lookup_local_variable(StringView name) const | |||
|     return nullptr; | ||||
| } | ||||
| 
 | ||||
| RefPtr<AST::Value> Shell::get_argument(size_t index) const | ||||
| RefPtr<AST::Value const> Shell::get_argument(size_t index) const | ||||
| { | ||||
|     if (index == 0) | ||||
|         return adopt_ref(*new AST::StringValue(current_script)); | ||||
|  | @ -369,7 +369,7 @@ RefPtr<AST::Value> 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<AST::ListValue*>(argv.ptr()); | ||||
|             AST::ListValue const* list = static_cast<AST::ListValue const*>(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<AST::Value&>(*value).resolve_as_list(const_cast<Shell&>(*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<AST::Value&>(*value).resolve_as_list(const_cast<Shell&>(*this)).contains_slow(command.argv[0]); | ||||
| } | ||||
| 
 | ||||
| void Shell::restore_ios() | ||||
|  | @ -1093,7 +1093,7 @@ void Shell::block_on_pipeline(RefPtr<AST::Pipeline> pipeline) | |||
| 
 | ||||
| void Shell::block_on_job(RefPtr<Job> job) | ||||
| { | ||||
|     TemporaryChange<Job const*> current_job { m_current_job, job.ptr() }; | ||||
|     TemporaryChange<Job*> current_job { m_current_job, job.ptr() }; | ||||
| 
 | ||||
|     if (!job) | ||||
|         return; | ||||
|  | @ -1671,7 +1671,7 @@ ErrorOr<Vector<Line::CompletionSuggestion>> 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<AST::Node&>(*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) { | ||||
|  |  | |||
|  | @ -170,8 +170,8 @@ public: | |||
| 
 | ||||
|     static bool has_history_event(StringView); | ||||
| 
 | ||||
|     RefPtr<AST::Value> get_argument(size_t) const; | ||||
|     RefPtr<AST::Value> lookup_local_variable(StringView) const; | ||||
|     RefPtr<AST::Value const> get_argument(size_t) const; | ||||
|     RefPtr<AST::Value const> lookup_local_variable(StringView) const; | ||||
|     DeprecatedString local_variable_or(StringView, DeprecatedString const&) const; | ||||
|     void set_local_variable(DeprecatedString const&, RefPtr<AST::Value>, 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 | ||||
|     { | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling