diff --git a/AK/NonnullRefPtr.h b/AK/NonnullRefPtr.h index b38b6528f5..192149373c 100644 --- a/AK/NonnullRefPtr.h +++ b/AK/NonnullRefPtr.h @@ -333,14 +333,14 @@ inline void swap(NonnullRefPtr& a, NonnullRefPtr& b) } template -requires(IsConstructible) inline NonnullRefPtr create(Args&&... args) +requires(IsConstructible) inline NonnullRefPtr make_ref_counted(Args&&... args) { return NonnullRefPtr(NonnullRefPtr::Adopt, *new T(forward(args)...)); } // FIXME: Remove once P0960R3 is available in Clang. template -inline NonnullRefPtr create(Args&&... args) +inline NonnullRefPtr make_ref_counted(Args&&... args) { return NonnullRefPtr(NonnullRefPtr::Adopt, *new T { forward(args)... }); } @@ -355,5 +355,5 @@ struct Traits> : public GenericTraits> { }; using AK::adopt_ref; -using AK::create; +using AK::make_ref_counted; using AK::NonnullRefPtr; diff --git a/AK/RefPtr.h b/AK/RefPtr.h index d5b17c3b2b..5031b82fe4 100644 --- a/AK/RefPtr.h +++ b/AK/RefPtr.h @@ -484,14 +484,14 @@ inline RefPtr adopt_ref_if_nonnull(T* object) } template -requires(IsConstructible) inline RefPtr try_create(Args&&... args) +requires(IsConstructible) inline RefPtr try_make_ref_counted(Args&&... args) { return adopt_ref_if_nonnull(new (nothrow) T(forward(args)...)); } // FIXME: Remove once P0960R3 is available in Clang. template -inline RefPtr try_create(Args&&... args) +inline RefPtr try_make_ref_counted(Args&&... args) { return adopt_ref_if_nonnull(new (nothrow) T { forward(args)... }); } @@ -512,7 +512,7 @@ inline Kernel::KResultOr> adopt_nonnull_ref_or_enomem(T* object using AK::adopt_ref_if_nonnull; using AK::RefPtr; using AK::static_ptr_cast; -using AK::try_create; +using AK::try_make_ref_counted; #ifdef KERNEL using AK::adopt_nonnull_ref_or_enomem; diff --git a/Kernel/Bus/USB/USBDevice.cpp b/Kernel/Bus/USB/USBDevice.cpp index ac3d175311..0f48152d98 100644 --- a/Kernel/Bus/USB/USBDevice.cpp +++ b/Kernel/Bus/USB/USBDevice.cpp @@ -22,7 +22,7 @@ KResultOr> Device::try_create(USBController const& control if (pipe_or_error.is_error()) return pipe_or_error.error(); - auto device = AK::try_create(controller, port, speed, pipe_or_error.release_value()); + auto device = try_make_ref_counted(controller, port, speed, pipe_or_error.release_value()); if (!device) return ENOMEM; diff --git a/Kernel/Bus/USB/USBHub.cpp b/Kernel/Bus/USB/USBHub.cpp index ef6cc67b71..d0c032f44c 100644 --- a/Kernel/Bus/USB/USBHub.cpp +++ b/Kernel/Bus/USB/USBHub.cpp @@ -19,7 +19,7 @@ KResultOr> Hub::try_create_root_hub(NonnullRefPtr(controller, device_speed, pipe_or_error.release_value()); + auto hub = try_make_ref_counted(controller, device_speed, pipe_or_error.release_value()); if (!hub) return ENOMEM; @@ -34,7 +34,7 @@ KResultOr> Hub::try_create_from_device(Device const& device) if (pipe_or_error.is_error()) return pipe_or_error.error(); - auto hub = AK::try_create(device, pipe_or_error.release_value()); + auto hub = try_make_ref_counted(device, pipe_or_error.release_value()); if (!hub) return ENOMEM; diff --git a/Kernel/Bus/USB/USBTransfer.cpp b/Kernel/Bus/USB/USBTransfer.cpp index 09a0959efb..c940a5de11 100644 --- a/Kernel/Bus/USB/USBTransfer.cpp +++ b/Kernel/Bus/USB/USBTransfer.cpp @@ -17,7 +17,7 @@ RefPtr Transfer::try_create(Pipe& pipe, u16 len) if (!data_buffer) return {}; - return AK::try_create(pipe, len, data_buffer.release_nonnull()); + return try_make_ref_counted(pipe, len, data_buffer.release_nonnull()); } Transfer::Transfer(Pipe& pipe, u16 len, NonnullOwnPtr data_buffer) diff --git a/Kernel/Memory/AnonymousVMObject.cpp b/Kernel/Memory/AnonymousVMObject.cpp index 8cd4915432..8a5559eb53 100644 --- a/Kernel/Memory/AnonymousVMObject.cpp +++ b/Kernel/Memory/AnonymousVMObject.cpp @@ -48,7 +48,7 @@ KResultOr> AnonymousVMObject::try_clone() // one would keep the one it still has. This ensures that the original // one and this one, as well as the clone have sufficient resources // to cow all pages as needed - auto new_shared_committed_cow_pages = try_create(committed_pages.release_value()); + auto new_shared_committed_cow_pages = try_make_ref_counted(committed_pages.release_value()); if (!new_shared_committed_cow_pages) return ENOMEM; diff --git a/Kernel/Thread.cpp b/Kernel/Thread.cpp index 8d14c8b959..bf45dea28a 100644 --- a/Kernel/Thread.cpp +++ b/Kernel/Thread.cpp @@ -44,7 +44,7 @@ KResultOr> Thread::try_create(NonnullRefPtr proce return ENOMEM; kernel_stack_region->set_stack(true); - auto block_timer = AK::try_create(); + auto block_timer = try_make_ref_counted(); if (!block_timer) return ENOMEM; diff --git a/Userland/Applications/Piano/Track.cpp b/Userland/Applications/Piano/Track.cpp index a51e7edeed..f077efc994 100644 --- a/Userland/Applications/Piano/Track.cpp +++ b/Userland/Applications/Piano/Track.cpp @@ -15,8 +15,8 @@ Track::Track(const u32& time) : m_time(time) - , m_temporary_transport(create(120, 4)) - , m_delay(create(m_temporary_transport)) + , m_temporary_transport(make_ref_counted(120, 4)) + , m_delay(make_ref_counted(m_temporary_transport)) { set_volume(volume_max); set_sustain_impl(1000); diff --git a/Userland/Applications/PixelPaint/Guide.h b/Userland/Applications/PixelPaint/Guide.h index 9592069270..6de1e5b59c 100644 --- a/Userland/Applications/PixelPaint/Guide.h +++ b/Userland/Applications/PixelPaint/Guide.h @@ -27,7 +27,7 @@ public: static NonnullRefPtr construct(Orientation orientation, float offset) { - return create(orientation, offset); + return make_ref_counted(orientation, offset); }; Orientation orientation() const { return m_orientation; } diff --git a/Userland/Applications/PixelPaint/GuideTool.cpp b/Userland/Applications/PixelPaint/GuideTool.cpp index 6e851af457..33007c4472 100644 --- a/Userland/Applications/PixelPaint/GuideTool.cpp +++ b/Userland/Applications/PixelPaint/GuideTool.cpp @@ -64,9 +64,9 @@ void GuideTool::on_mousedown(Layer*, MouseEvent& event) RefPtr new_guide; if (image_event.position().x() < 0 || image_event.position().x() > editor()->image().size().width()) { - new_guide = Guide::construct(Guide::Orientation::Vertical, image_event.position().x()); + new_guide = make_ref_counted(Guide::Orientation::Vertical, image_event.position().x()); } else if (image_event.position().y() < 0 || image_event.position().y() > editor()->image().size().height()) { - new_guide = Guide::construct(Guide::Orientation::Horizontal, image_event.position().y()); + new_guide = make_ref_counted(Guide::Orientation::Horizontal, image_event.position().y()); } if (new_guide) { diff --git a/Userland/DevTools/HackStudio/LanguageServers/Shell/ShellComprehensionEngine.cpp b/Userland/DevTools/HackStudio/LanguageServers/Shell/ShellComprehensionEngine.cpp index fa7cc39f5a..0078c6c60f 100644 --- a/Userland/DevTools/HackStudio/LanguageServers/Shell/ShellComprehensionEngine.cpp +++ b/Userland/DevTools/HackStudio/LanguageServers/Shell/ShellComprehensionEngine.cpp @@ -107,7 +107,7 @@ NonnullRefPtr<::Shell::AST::Node> ShellComprehensionEngine::DocumentData::parse( if (auto node = parser.parse()) return node.release_nonnull(); - return ::Shell::AST::create<::Shell::AST::SyntaxError>(::Shell::AST::Position {}, "Unable to parse file"); + return ::Shell::AST::make_ref_counted<::Shell::AST::SyntaxError>(::Shell::AST::Position {}, "Unable to parse file"); } size_t ShellComprehensionEngine::resolve(const ShellComprehensionEngine::DocumentData& document, const GUI::TextPosition& position) diff --git a/Userland/Libraries/LibJS/Parser.cpp b/Userland/Libraries/LibJS/Parser.cpp index d1528e64f9..c2cf37f9dc 100644 --- a/Userland/Libraries/LibJS/Parser.cpp +++ b/Userland/Libraries/LibJS/Parser.cpp @@ -44,7 +44,7 @@ public: if (m_mask & Let) m_parser.m_state.let_scopes.append(NonnullRefPtrVector()); - m_parser.m_state.current_scope = create(scope_type, m_parser.m_state.current_scope); + m_parser.m_state.current_scope = make_ref_counted(scope_type, m_parser.m_state.current_scope); } ~ScopePusher() diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index b4e240e89a..9b913b17c2 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -707,7 +707,7 @@ NonnullRefPtr Parser::consume_an_at_rule(TokenStream& tokens) auto& name_ident = tokens.next_token(); VERIFY(name_ident.is(Token::Type::AtKeyword)); - NonnullRefPtr rule = create(StyleRule::Type::At); + auto rule = make_ref_counted(StyleRule::Type::At); rule->m_name = ((Token)name_ident).at_keyword(); for (;;) { @@ -744,7 +744,7 @@ RefPtr Parser::consume_a_qualified_rule(TokenStream& tokens) { dbgln_if(CSS_PARSER_DEBUG, "Parser::consume_a_qualified_rule"); - NonnullRefPtr rule = create(StyleRule::Type::Qualified); + auto rule = make_ref_counted(StyleRule::Type::Qualified); for (;;) { auto& token = tokens.next_token(); @@ -810,7 +810,7 @@ NonnullRefPtr Parser::consume_a_simple_block(TokenStream& tok auto ending_token = ((Token)tokens.current_token()).mirror_variant(); - NonnullRefPtr block = create(); + auto block = make_ref_counted(); block->m_token = tokens.current_token(); for (;;) { @@ -843,7 +843,7 @@ NonnullRefPtr Parser::consume_a_function(TokenStream& toke auto name_ident = tokens.current_token(); VERIFY(name_ident.is(Token::Type::Function)); - NonnullRefPtr function = create(((Token)name_ident).m_value.to_string()); + auto function = make_ref_counted(((Token)name_ident).m_value.to_string()); for (;;) { auto& token = tokens.next_token(); diff --git a/Userland/Shell/AST.cpp b/Userland/Shell/AST.cpp index e8fc60246b..24688d32c7 100644 --- a/Userland/Shell/AST.cpp +++ b/Userland/Shell/AST.cpp @@ -286,7 +286,7 @@ void Node::for_each_entry(RefPtr shell, Functionresolve_as_list(shell); for (auto& element : list) { - if (callback(create(move(element))) == IterationDecision::Break) + if (callback(make_ref_counted(move(element))) == IterationDecision::Break) break; } } @@ -390,7 +390,7 @@ RefPtr And::run(RefPtr shell) { auto commands = m_left->to_lazy_evaluated_commands(shell); commands.last().next_chain.append(NodeWithAction { *m_right, NodeWithAction::And }); - return create(move(commands)); + return make_ref_counted(move(commands)); } void And::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata) @@ -444,7 +444,7 @@ RefPtr ListConcatenate::run(RefPtr shell) for (auto& element : m_list) { if (!result) { - result = create({ element->run(shell)->resolve_without_cast(shell) }); + result = make_ref_counted({ element->run(shell)->resolve_without_cast(shell) }); continue; } auto element_value = element->run(shell)->resolve_without_cast(shell); @@ -455,9 +455,9 @@ RefPtr ListConcatenate::run(RefPtr shell) if (joined_commands.size() == 1) { auto& command = joined_commands[0]; command.position = position(); - result = create(command); + result = make_ref_counted(command); } else { - result = create(move(joined_commands)); + result = make_ref_counted(move(joined_commands)); } } else { NonnullRefPtrVector values; @@ -466,16 +466,16 @@ RefPtr ListConcatenate::run(RefPtr shell) values.extend(static_cast(result.ptr())->values()); } else { for (auto& result : result->resolve_as_list(shell)) - values.append(create(result)); + values.append(make_ref_counted(result)); } values.append(element_value); - result = create(move(values)); + result = make_ref_counted(move(values)); } } if (!result) - return create({}); + return make_ref_counted({}); return result; } @@ -554,7 +554,7 @@ RefPtr Background::run(RefPtr shell) for (auto& command : commands) command.should_wait = false; - return create(move(commands)); + return make_ref_counted(move(commands)); } void Background::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata) @@ -587,7 +587,7 @@ void BarewordLiteral::dump(int level) const RefPtr BarewordLiteral::run(RefPtr) { - return create(m_text); + return make_ref_counted(m_text); } void BarewordLiteral::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata) @@ -651,7 +651,7 @@ RefPtr BraceExpansion::run(RefPtr shell) values.append(value.release_nonnull()); } - return create(move(values)); + return make_ref_counted(move(values)); } HitTestResult BraceExpansion::hit_test_position(size_t offset) const @@ -708,7 +708,7 @@ RefPtr CastToCommand::run(RefPtr shell) return value; auto argv = value->resolve_as_list(shell); - return create(move(argv), position()); + return make_ref_counted(move(argv), position()); } void CastToCommand::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata) @@ -768,7 +768,7 @@ void CastToList::dump(int level) const RefPtr CastToList::run(RefPtr shell) { if (!m_inner) - return create({}); + return make_ref_counted({}); auto inner_value = m_inner->run(shell)->resolve_without_cast(shell); @@ -778,9 +778,9 @@ RefPtr CastToList::run(RefPtr shell) auto values = inner_value->resolve_as_list(shell); NonnullRefPtrVector cast_values; for (auto& value : values) - cast_values.append(create(value)); + cast_values.append(make_ref_counted(value)); - return create(cast_values); + return make_ref_counted(cast_values); } void CastToList::for_each_entry(RefPtr shell, Function)> callback) @@ -831,7 +831,7 @@ RefPtr CloseFdRedirection::run(RefPtr) Command command; command.position = position(); command.redirections.append(adopt_ref(*new CloseRedirection(m_fd))); - return create(move(command)); + return make_ref_counted(move(command)); } void CloseFdRedirection::highlight_in_editor(Line::Editor& editor, Shell&, HighlightMetadata) @@ -858,7 +858,7 @@ void CommandLiteral::dump(int level) const RefPtr CommandLiteral::run(RefPtr) { - return create(m_command); + return make_ref_counted(m_command); } CommandLiteral::CommandLiteral(Position position, Command command) @@ -879,7 +879,7 @@ void Comment::dump(int level) const RefPtr Comment::run(RefPtr) { - return create({}); + return make_ref_counted({}); } void Comment::highlight_in_editor(Line::Editor& editor, Shell&, HighlightMetadata) @@ -911,7 +911,7 @@ RefPtr ContinuationControl::run(RefPtr shell) shell->raise_error(Shell::ShellError::InternalControlFlowContinue, {}, position()); else VERIFY_NOT_REACHED(); - return create({}); + return make_ref_counted({}); } void ContinuationControl::highlight_in_editor(Line::Editor& editor, Shell&, HighlightMetadata) @@ -932,7 +932,7 @@ RefPtr DoubleQuotedString::run(RefPtr shell) builder.join("", values); - return create(builder.to_string()); + return make_ref_counted(builder.to_string()); } void DoubleQuotedString::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata) @@ -977,12 +977,12 @@ RefPtr DynamicEvaluate::run(RefPtr shell) if (result->is_string()) { auto name_part = result->resolve_as_list(shell); VERIFY(name_part.size() == 1); - return create(name_part[0]); + return make_ref_counted(name_part[0]); } // If it's anything else, we're just gonna cast it to a list. auto list = result->resolve_as_list(shell); - return create(move(list), position()); + return make_ref_counted(move(list), position()); } void DynamicEvaluate::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata) @@ -1019,7 +1019,7 @@ RefPtr Fd2FdRedirection::run(RefPtr) Command command; command.position = position(); command.redirections.append(FdRedirection::create(m_new_fd, m_old_fd, Rewiring::Close::None)); - return create(move(command)); + return make_ref_counted(move(command)); } void Fd2FdRedirection::highlight_in_editor(Line::Editor& editor, Shell&, HighlightMetadata) @@ -1061,7 +1061,7 @@ RefPtr FunctionDeclaration::run(RefPtr shell) shell->define_function(m_name.name, move(args), m_block); - return create({}); + return make_ref_counted({}); } void FunctionDeclaration::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata) @@ -1147,7 +1147,7 @@ void ForLoop::dump(int level) const RefPtr ForLoop::run(RefPtr shell) { if (!m_block) - return create({}); + return make_ref_counted({}); size_t consecutive_interruptions = 0; auto run = [&](auto& block_value) { @@ -1197,7 +1197,7 @@ RefPtr ForLoop::run(RefPtr shell) shell->set_local_variable(variable_name, value, true); if (index_name.has_value()) - shell->set_local_variable(index_name.value(), create(String::number(i)), true); + shell->set_local_variable(index_name.value(), make_ref_counted(String::number(i)), true); ++i; @@ -1217,7 +1217,7 @@ RefPtr ForLoop::run(RefPtr shell) } } - return create({}); + return make_ref_counted({}); } void ForLoop::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata) @@ -1286,7 +1286,7 @@ void Glob::dump(int level) const RefPtr Glob::run(RefPtr) { - return create(m_text, position()); + return make_ref_counted(m_text, position()); } void Glob::highlight_in_editor(Line::Editor& editor, Shell&, HighlightMetadata metadata) @@ -1342,7 +1342,7 @@ RefPtr Heredoc::run(RefPtr shell) builder.append('\n'); } - return create(builder.to_string()); + return make_ref_counted(builder.to_string()); } void Heredoc::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata) @@ -1425,12 +1425,12 @@ void HistoryEvent::dump(int level) const RefPtr HistoryEvent::run(RefPtr shell) { if (!shell) - return create({}); + return make_ref_counted({}); auto editor = shell->editor(); if (!editor) { shell->raise_error(Shell::ShellError::EvaluatedSyntaxError, "No history available!", position()); - return create({}); + return make_ref_counted({}); } auto& history = editor->history(); @@ -1450,14 +1450,14 @@ RefPtr HistoryEvent::run(RefPtr shell) case HistorySelector::EventKind::IndexFromStart: if (m_selector.event.index >= history.size()) { shell->raise_error(Shell::ShellError::EvaluatedSyntaxError, "History event index out of bounds", m_selector.event.text_position); - return create({}); + return make_ref_counted({}); } resolved_history = history[m_selector.event.index].entry; break; case HistorySelector::EventKind::IndexFromEnd: if (m_selector.event.index >= history.size()) { shell->raise_error(Shell::ShellError::EvaluatedSyntaxError, "History event index out of bounds", m_selector.event.text_position); - return create({}); + return make_ref_counted({}); } resolved_history = history[history.size() - m_selector.event.index - 1].entry; break; @@ -1465,7 +1465,7 @@ RefPtr HistoryEvent::run(RefPtr shell) auto it = find_reverse(history.begin(), history.end(), [&](auto& entry) { return entry.entry.contains(m_selector.event.text); }); if (it.is_end()) { shell->raise_error(Shell::ShellError::EvaluatedSyntaxError, "History event did not match any entry", m_selector.event.text_position); - return create({}); + return make_ref_counted({}); } resolved_history = it->entry; break; @@ -1474,7 +1474,7 @@ RefPtr HistoryEvent::run(RefPtr shell) auto it = find_reverse(history.begin(), history.end(), [&](auto& entry) { return entry.entry.starts_with(m_selector.event.text); }); if (it.is_end()) { shell->raise_error(Shell::ShellError::EvaluatedSyntaxError, "History event did not match any entry", m_selector.event.text_position); - return create({}); + return make_ref_counted({}); } resolved_history = it->entry; break; @@ -1491,23 +1491,23 @@ RefPtr HistoryEvent::run(RefPtr shell) auto end_index = m_selector.word_selector_range.end->resolve(nodes.size()); if (start_index >= nodes.size()) { shell->raise_error(Shell::ShellError::EvaluatedSyntaxError, "History word index out of bounds", m_selector.word_selector_range.start.position); - return create({}); + return make_ref_counted({}); } if (end_index >= nodes.size()) { shell->raise_error(Shell::ShellError::EvaluatedSyntaxError, "History word index out of bounds", m_selector.word_selector_range.end->position); - return create({}); + return make_ref_counted({}); } decltype(nodes) resolved_nodes; resolved_nodes.append(nodes.data() + start_index, end_index - start_index + 1); - NonnullRefPtr list = create(position(), move(resolved_nodes)); + NonnullRefPtr list = make_ref_counted(position(), move(resolved_nodes)); return list->run(shell); } auto index = m_selector.word_selector_range.start.resolve(nodes.size()); if (index >= nodes.size()) { shell->raise_error(Shell::ShellError::EvaluatedSyntaxError, "History word index out of bounds", m_selector.word_selector_range.start.position); - return create({}); + return make_ref_counted({}); } return nodes[index].run(shell); } @@ -1583,7 +1583,7 @@ void Execute::for_each_entry(RefPtr shell, Functionoptions.inline_exec_keep_empty_segments) - if (callback(create("")) == IterationDecision::Break) { + if (callback(make_ref_counted("")) == IterationDecision::Break) { loop.quit(Break); notifier->set_enabled(false); return Break; @@ -1594,7 +1594,7 @@ void Execute::for_each_entry(RefPtr shell, Function(str)) == IterationDecision::Break) { + if (callback(make_ref_counted(str)) == IterationDecision::Break) { loop.quit(Break); notifier->set_enabled(false); return Break; @@ -1678,7 +1678,7 @@ void Execute::for_each_entry(RefPtr shell, Function(String::copy(entry))); + callback(make_ref_counted(String::copy(entry))); } } @@ -1688,7 +1688,7 @@ void Execute::for_each_entry(RefPtr shell, Functionrun_commands(commands); if (!jobs.is_empty()) - callback(create(&jobs.last())); + callback(make_ref_counted(&jobs.last())); } RefPtr Execute::run(RefPtr shell) @@ -1705,7 +1705,7 @@ RefPtr Execute::run(RefPtr shell) if (values.size() == 1 && values.first().is_job()) return values.first(); - return create(move(values)); + return make_ref_counted(move(values)); } void Execute::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata) @@ -1789,7 +1789,7 @@ RefPtr IfCond::run(RefPtr shell) return m_false_branch->run(shell); } - return create({}); + return make_ref_counted({}); } void IfCond::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata) @@ -1839,7 +1839,7 @@ IfCond::IfCond(Position position, Optional else_position, NonnullRefPt else if (m_false_branch && m_false_branch->is_syntax_error()) set_is_syntax_error(m_false_branch->syntax_error_node()); - m_condition = create(m_condition->position(), m_condition); + m_condition = make_ref_counted(m_condition->position(), m_condition); if (m_true_branch) { auto true_branch = m_true_branch.release_nonnull(); @@ -1878,7 +1878,7 @@ RefPtr ImmediateExpression::run(RefPtr shell) if (node) return node->run(shell); - return create({}); + return make_ref_counted({}); } void ImmediateExpression::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata) @@ -1963,7 +1963,7 @@ RefPtr Join::run(RefPtr shell) auto left = m_left->to_lazy_evaluated_commands(shell); auto right = m_right->to_lazy_evaluated_commands(shell); - return create(join_commands(move(left), move(right))); + return make_ref_counted(join_commands(move(left), move(right))); } void Join::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata) @@ -2091,20 +2091,20 @@ RefPtr MatchExpr::run(RefPtr shell) size_t i = 0; for (auto& name : entry.match_names.value()) { if (spans.size() > i) - shell->set_local_variable(name, create(spans[i]), true); + shell->set_local_variable(name, make_ref_counted(spans[i]), true); ++i; } } return entry.body->run(shell); } else { - return create({}); + return make_ref_counted({}); } } } } shell->raise_error(Shell::ShellError::EvaluatedSyntaxError, "Non-exhaustive match rules!", position()); - return create({}); + return make_ref_counted({}); } void MatchExpr::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata) @@ -2186,7 +2186,7 @@ RefPtr Or::run(RefPtr shell) { auto commands = m_left->to_lazy_evaluated_commands(shell); commands.last().next_chain.empend(*m_right, NodeWithAction::Or); - return create(move(commands)); + return make_ref_counted(move(commands)); } void Or::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata) @@ -2270,7 +2270,7 @@ RefPtr Pipe::run(RefPtr shell) if (first_in_right.pipeline) { last_in_left.pipeline = first_in_right.pipeline; } else { - auto pipeline = create(); + auto pipeline = make_ref_counted(); last_in_left.pipeline = pipeline; first_in_right.pipeline = pipeline; } @@ -2281,7 +2281,7 @@ RefPtr Pipe::run(RefPtr shell) commands.append(first_in_right); commands.extend(right); - return create(move(commands)); + return make_ref_counted(move(commands)); } void Pipe::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata) @@ -2402,12 +2402,12 @@ RefPtr Range::run(RefPtr shell) for (u32 code_point = start_code_point; code_point != end_code_point; code_point += step) { builder.clear(); builder.append_code_point(code_point); - values.append(create(builder.to_string())); + values.append(make_ref_counted(builder.to_string())); } // Append the ending code point too, most shells treat this as inclusive. builder.clear(); builder.append_code_point(end_code_point); - values.append(create(builder.to_string())); + values.append(make_ref_counted(builder.to_string())); } else { // Could be two numbers? auto start_int = start_str.to_int(); @@ -2417,9 +2417,9 @@ RefPtr Range::run(RefPtr shell) auto end = end_int.value(); auto step = start > end ? -1 : 1; for (int value = start; value != end; value += step) - values.append(create(String::number(value))); + values.append(make_ref_counted(String::number(value))); // Append the range end too, most shells treat this as inclusive. - values.append(create(String::number(end))); + values.append(make_ref_counted(String::number(end))); } else { goto yield_start_end; } @@ -2428,8 +2428,8 @@ RefPtr Range::run(RefPtr shell) yield_start_end:; shell->raise_error(Shell::ShellError::EvaluatedSyntaxError, String::formatted("Cannot interpolate between '{}' and '{}'!", start_str, end_str), position); // We can't really interpolate between the two, so just yield both. - values.append(create(move(start_str))); - values.append(create(move(end_str))); + values.append(make_ref_counted(move(start_str))); + values.append(make_ref_counted(move(end_str))); } return values; @@ -2442,9 +2442,9 @@ RefPtr Range::run(RefPtr shell) auto start_value = m_start->run(shell); auto end_value = m_end->run(shell); if (!start_value || !end_value) - return create({}); + return make_ref_counted({}); - return create(interpolate(*start_value, *end_value, shell)); + return make_ref_counted(interpolate(*start_value, *end_value, shell)); } void Range::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata) @@ -2503,7 +2503,7 @@ RefPtr ReadRedirection::run(RefPtr shell) builder.join(" ", path_segments); command.redirections.append(PathRedirection::create(builder.to_string(), m_fd, PathRedirection::Read)); - return create(move(command)); + return make_ref_counted(move(command)); } ReadRedirection::ReadRedirection(Position position, int fd, NonnullRefPtr path) @@ -2530,7 +2530,7 @@ RefPtr ReadWriteRedirection::run(RefPtr shell) builder.join(" ", path_segments); command.redirections.append(PathRedirection::create(builder.to_string(), m_fd, PathRedirection::ReadWrite)); - return create(move(command)); + return make_ref_counted(move(command)); } ReadWriteRedirection::ReadWriteRedirection(Position position, int fd, NonnullRefPtr path) @@ -2569,7 +2569,7 @@ RefPtr Sequence::run(RefPtr shell) } } - return create(move(all_commands)); + return make_ref_counted(move(all_commands)); } void Sequence::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata) @@ -2619,9 +2619,9 @@ void Subshell::dump(int level) const RefPtr Subshell::run(RefPtr shell) { if (!m_block) - return create({}); + return make_ref_counted({}); - return create(m_block->to_lazy_evaluated_commands(shell)); + return make_ref_counted(m_block->to_lazy_evaluated_commands(shell)); } void Subshell::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata) @@ -2704,7 +2704,7 @@ void SimpleVariable::dump(int level) const RefPtr SimpleVariable::run(RefPtr) { - NonnullRefPtr value = create(m_name); + NonnullRefPtr value = make_ref_counted(m_name); if (m_slice) value = value->with_slices(*m_slice); return value; @@ -2769,7 +2769,7 @@ void SpecialVariable::dump(int level) const RefPtr SpecialVariable::run(RefPtr) { - NonnullRefPtr value = create(m_name); + NonnullRefPtr value = make_ref_counted(m_name); if (m_slice) value = value->with_slices(*m_slice); return value; @@ -2829,12 +2829,12 @@ RefPtr Juxtaposition::run(RefPtr shell) builder.append(left[0]); builder.append(right[0]); - return create(builder.to_string()); + return make_ref_counted(builder.to_string()); } // Otherwise, treat them as lists and create a list product. if (left.is_empty() || right.is_empty()) - return create({}); + return make_ref_counted({}); Vector result; result.ensure_capacity(left.size() * right.size()); @@ -2849,7 +2849,7 @@ RefPtr Juxtaposition::run(RefPtr shell) } } - return create(move(result)); + return make_ref_counted(move(result)); } void Juxtaposition::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata) @@ -2940,7 +2940,7 @@ void StringLiteral::dump(int level) const RefPtr StringLiteral::run(RefPtr) { - return create(m_text); + return make_ref_counted(m_text); } void StringLiteral::highlight_in_editor(Line::Editor& editor, Shell&, HighlightMetadata metadata) @@ -2980,7 +2980,7 @@ RefPtr StringPartCompose::run(RefPtr shell) builder.join(" ", left); builder.join(" ", right); - return create(builder.to_string()); + return make_ref_counted(builder.to_string()); } void StringPartCompose::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata) @@ -3024,7 +3024,7 @@ void SyntaxError::dump(int level) const RefPtr SyntaxError::run(RefPtr shell) { shell->raise_error(Shell::ShellError::EvaluatedSyntaxError, m_syntax_error_text, position()); - return create(""); + return make_ref_counted(""); } void SyntaxError::highlight_in_editor(Line::Editor& editor, Shell&, HighlightMetadata) @@ -3076,7 +3076,7 @@ void Tilde::dump(int level) const RefPtr Tilde::run(RefPtr) { - return create(m_username); + return make_ref_counted(m_username); } void Tilde::highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata) @@ -3141,7 +3141,7 @@ RefPtr WriteAppendRedirection::run(RefPtr shell) builder.join(" ", path_segments); command.redirections.append(PathRedirection::create(builder.to_string(), m_fd, PathRedirection::WriteAppend)); - return create(move(command)); + return make_ref_counted(move(command)); } WriteAppendRedirection::WriteAppendRedirection(Position position, int fd, NonnullRefPtr path) @@ -3168,7 +3168,7 @@ RefPtr WriteRedirection::run(RefPtr shell) builder.join(" ", path_segments); command.redirections.append(PathRedirection::create(builder.to_string(), m_fd, PathRedirection::Write)); - return create(move(command)); + return make_ref_counted(move(command)); } WriteRedirection::WriteRedirection(Position position, int fd, NonnullRefPtr path) @@ -3200,7 +3200,7 @@ RefPtr VariableDeclarations::run(RefPtr shell) shell->set_local_variable(name, value.release_nonnull()); } - return create({}); + return make_ref_counted({}); } void VariableDeclarations::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata) @@ -3297,7 +3297,7 @@ NonnullRefPtr ListValue::resolve_without_cast(RefPtr shell) for (auto& value : m_contained_values) values.append(value.resolve_without_cast(shell)); - NonnullRefPtr value = create(move(values)); + NonnullRefPtr value = make_ref_counted(move(values)); if (!m_slices.is_empty()) value = value->with_slices(m_slices); return value; @@ -3357,7 +3357,7 @@ Vector StringValue::resolve_as_list(RefPtr shell) NonnullRefPtr StringValue::resolve_without_cast(RefPtr shell) { if (is_list()) - return create(resolve_as_list(shell)); // No need to reapply the slices. + return make_ref_counted(resolve_as_list(shell)); // No need to reapply the slices. return *this; } diff --git a/Userland/Shell/AST.h b/Userland/Shell/AST.h index d11f591a95..ce6d286412 100644 --- a/Userland/Shell/AST.h +++ b/Userland/Shell/AST.h @@ -20,10 +20,10 @@ namespace Shell::AST { -using AK::create; +using AK::make_ref_counted; template -static inline NonnullRefPtr create(std::initializer_list> arg) +static inline NonnullRefPtr make_ref_counted(std::initializer_list> arg) { return adopt_ref(*new T(arg)); } @@ -243,7 +243,7 @@ class CommandValue final : public Value { public: virtual Vector resolve_as_list(RefPtr) override; virtual Vector resolve_as_commands(RefPtr) override; - virtual NonnullRefPtr clone() const override { return create(m_command)->set_slices(m_slices); } + virtual NonnullRefPtr clone() const override { return make_ref_counted(m_command)->set_slices(m_slices); } virtual ~CommandValue(); virtual bool is_command() const override { return true; } CommandValue(Command command) @@ -264,7 +264,7 @@ class CommandSequenceValue final : public Value { public: virtual Vector resolve_as_list(RefPtr) override; virtual Vector resolve_as_commands(RefPtr) override; - virtual NonnullRefPtr clone() const override { return create(m_contained_values)->set_slices(m_slices); } + virtual NonnullRefPtr clone() const override { return make_ref_counted(m_contained_values)->set_slices(m_slices); } virtual ~CommandSequenceValue(); virtual bool is_command() const override { return true; } CommandSequenceValue(Vector commands) @@ -280,7 +280,7 @@ class JobValue final : public Value { public: virtual Vector resolve_as_list(RefPtr) override { VERIFY_NOT_REACHED(); } virtual Vector resolve_as_commands(RefPtr) override { VERIFY_NOT_REACHED(); } - virtual NonnullRefPtr clone() const override { return create(m_job)->set_slices(m_slices); } + virtual NonnullRefPtr clone() const override { return make_ref_counted(m_job)->set_slices(m_slices); } virtual ~JobValue(); virtual bool is_job() const override { return true; } JobValue(RefPtr job) @@ -298,7 +298,7 @@ class ListValue final : public Value { public: virtual Vector resolve_as_list(RefPtr) override; virtual NonnullRefPtr resolve_without_cast(RefPtr) override; - virtual NonnullRefPtr clone() const override { return create(m_contained_values)->set_slices(m_slices); } + virtual NonnullRefPtr clone() const override { return make_ref_counted(m_contained_values)->set_slices(m_slices); } virtual ~ListValue(); virtual bool is_list() const override { return true; } virtual bool is_list_without_resolution() const override { return true; } @@ -322,7 +322,7 @@ private: class StringValue final : public Value { public: virtual Vector resolve_as_list(RefPtr) override; - virtual NonnullRefPtr clone() const override { return create(m_string, m_split, m_keep_empty)->set_slices(m_slices); } + virtual NonnullRefPtr clone() const override { return make_ref_counted(m_string, m_split, m_keep_empty)->set_slices(m_slices); } virtual ~StringValue(); virtual bool is_string() const override { return m_split.is_null(); } virtual bool is_list() const override { return !m_split.is_null(); } @@ -343,7 +343,7 @@ private: class GlobValue final : public Value { public: virtual Vector resolve_as_list(RefPtr) override; - virtual NonnullRefPtr clone() const override { return create(m_glob, m_generation_position)->set_slices(m_slices); } + virtual NonnullRefPtr clone() const override { return make_ref_counted(m_glob, m_generation_position)->set_slices(m_slices); } virtual ~GlobValue(); virtual bool is_glob() const override { return true; } GlobValue(String glob, Position position) @@ -361,7 +361,7 @@ class SimpleVariableValue final : public Value { public: virtual Vector resolve_as_list(RefPtr) override; virtual NonnullRefPtr resolve_without_cast(RefPtr) override; - virtual NonnullRefPtr clone() const override { return create(m_name)->set_slices(m_slices); } + virtual NonnullRefPtr clone() const override { return make_ref_counted(m_name)->set_slices(m_slices); } virtual ~SimpleVariableValue(); SimpleVariableValue(String name) : m_name(move(name)) @@ -375,7 +375,7 @@ private: class SpecialVariableValue final : public Value { public: virtual Vector resolve_as_list(RefPtr) override; - virtual NonnullRefPtr clone() const override { return create(m_name)->set_slices(m_slices); } + virtual NonnullRefPtr clone() const override { return make_ref_counted(m_name)->set_slices(m_slices); } virtual ~SpecialVariableValue(); SpecialVariableValue(char name) : m_name(name) @@ -389,7 +389,7 @@ private: class TildeValue final : public Value { public: virtual Vector resolve_as_list(RefPtr) override; - virtual NonnullRefPtr clone() const override { return create(m_username)->set_slices(m_slices); } + virtual NonnullRefPtr clone() const override { return make_ref_counted(m_username)->set_slices(m_slices); } virtual ~TildeValue(); virtual bool is_string() const override { return true; } TildeValue(String name) diff --git a/Userland/Shell/Builtin.cpp b/Userland/Shell/Builtin.cpp index 1dbfa41af2..e3671d38e8 100644 --- a/Userland/Shell/Builtin.cpp +++ b/Userland/Shell/Builtin.cpp @@ -868,7 +868,7 @@ int Shell::builtin_source(int argc, const char** argv) } }; if (!args.is_empty()) - set_local_variable("ARGV", AST::create(move(string_argv))); + set_local_variable("ARGV", AST::make_ref_counted(move(string_argv))); if (!run_file(file_to_source, true)) return 126; diff --git a/Userland/Shell/ImmediateFunctions.cpp b/Userland/Shell/ImmediateFunctions.cpp index edb926f608..1ca9f8f281 100644 --- a/Userland/Shell/ImmediateFunctions.cpp +++ b/Userland/Shell/ImmediateFunctions.cpp @@ -67,7 +67,7 @@ RefPtr Shell::immediate_length_impl(AST::ImmediateExpression& invokin } auto value_with_number = [&](auto number) -> NonnullRefPtr { - return AST::create(invoking_node.position(), String::number(number)); + return AST::make_ref_counted(invoking_node.position(), String::number(number)); }; auto do_across = [&](StringView mode_name, auto& values) { @@ -78,17 +78,17 @@ RefPtr Shell::immediate_length_impl(AST::ImmediateExpression& invokin resulting_nodes.ensure_capacity(values.size()); for (auto& entry : values) { // ImmediateExpression(length ) - resulting_nodes.unchecked_append(AST::create( + resulting_nodes.unchecked_append(AST::make_ref_counted( expr_node->position(), AST::NameWithPosition { "length", invoking_node.function_position() }, NonnullRefPtrVector { Vector> { - static_cast>(AST::create(expr_node->position(), mode_name)), - AST::create(expr_node->position(), NonnullRefPtr(entry)), + static_cast>(AST::make_ref_counted(expr_node->position(), mode_name)), + AST::make_ref_counted(expr_node->position(), NonnullRefPtr(entry)), } }, expr_node->position())); } - return AST::create(invoking_node.position(), move(resulting_nodes)); + return AST::make_ref_counted(invoking_node.position(), move(resulting_nodes)); }; switch (mode) { @@ -114,7 +114,7 @@ RefPtr Shell::immediate_length_impl(AST::ImmediateExpression& invokin return value_with_number(list.size()); dbgln("List has {} entries", list.size()); - auto values = AST::create(move(list)); + auto values = AST::make_ref_counted(move(list)); return do_across("list", values->values()); } case String: { @@ -183,7 +183,7 @@ RefPtr Shell::immediate_length_impl(AST::ImmediateExpression& invokin return nullptr; } - auto values = AST::create(move(list)); + auto values = AST::make_ref_counted(move(list)); return do_across("string", values->values()); } } @@ -228,7 +228,7 @@ RefPtr Shell::immediate_regex_replace(AST::ImmediateExpression& invok Regex re { pattern->resolve_as_list(this).first() }; auto result = re.replace(value->resolve_as_list(this)[0], replacement->resolve_as_list(this)[0], PosixFlags::Global | PosixFlags::Multiline | PosixFlags::Unicode); - return AST::create(invoking_node.position(), move(result)); + return AST::make_ref_counted(invoking_node.position(), move(result)); } RefPtr Shell::immediate_remove_suffix(AST::ImmediateExpression& invoking_node, const NonnullRefPtrVector& arguments) @@ -256,10 +256,10 @@ RefPtr Shell::immediate_remove_suffix(AST::ImmediateExpression& invok if (value_str.ends_with(suffix_str)) removed = removed.substring_view(0, value_str.length() - suffix_str.length()); - nodes.append(AST::create(invoking_node.position(), removed)); + nodes.append(AST::make_ref_counted(invoking_node.position(), removed)); } - return AST::create(invoking_node.position(), move(nodes)); + return AST::make_ref_counted(invoking_node.position(), move(nodes)); } RefPtr Shell::immediate_remove_prefix(AST::ImmediateExpression& invoking_node, const NonnullRefPtrVector& arguments) @@ -287,10 +287,10 @@ RefPtr Shell::immediate_remove_prefix(AST::ImmediateExpression& invok if (value_str.starts_with(prefix_str)) removed = removed.substring_view(prefix_str.length()); - nodes.append(AST::create(invoking_node.position(), removed)); + nodes.append(AST::make_ref_counted(invoking_node.position(), removed)); } - return AST::create(invoking_node.position(), move(nodes)); + return AST::make_ref_counted(invoking_node.position(), move(nodes)); } RefPtr Shell::immediate_split(AST::ImmediateExpression& invoking_node, const NonnullRefPtrVector& arguments) @@ -316,17 +316,17 @@ RefPtr Shell::immediate_split(AST::ImmediateExpression& invoking_node resulting_nodes.ensure_capacity(values.size()); for (auto& entry : values) { // ImmediateExpression(split ) - resulting_nodes.unchecked_append(AST::create( + resulting_nodes.unchecked_append(AST::make_ref_counted( arguments[1].position(), invoking_node.function(), NonnullRefPtrVector { Vector> { arguments[0], - AST::create(arguments[1].position(), NonnullRefPtr(entry)), + AST::make_ref_counted(arguments[1].position(), NonnullRefPtr(entry)), } }, arguments[1].position())); } - return AST::create(invoking_node.position(), move(resulting_nodes)); + return AST::make_ref_counted(invoking_node.position(), move(resulting_nodes)); }; if (auto list = dynamic_cast(value.ptr())) { @@ -337,7 +337,7 @@ RefPtr Shell::immediate_split(AST::ImmediateExpression& invoking_node auto list = value->resolve_as_list(this); if (!value->is_list()) { if (list.is_empty()) - return AST::create(invoking_node.position(), NonnullRefPtrVector {}); + return AST::make_ref_counted(invoking_node.position(), NonnullRefPtrVector {}); auto& value = list.first(); Vector split_strings; @@ -354,10 +354,10 @@ RefPtr Shell::immediate_split(AST::ImmediateExpression& invoking_node for (auto& entry : split) split_strings.append(entry); } - return AST::create(invoking_node.position(), AST::create(move(split_strings))); + return AST::make_ref_counted(invoking_node.position(), AST::make_ref_counted(move(split_strings))); } - return transform(AST::create(list)->values()); + return transform(AST::make_ref_counted(list)->values()); } RefPtr Shell::immediate_concat_lists(AST::ImmediateExpression& invoking_node, const NonnullRefPtrVector& arguments) @@ -371,16 +371,16 @@ RefPtr Shell::immediate_concat_lists(AST::ImmediateExpression& invoki auto list_of_values = const_cast(argument).run(this)->resolve_without_cast(this); if (auto* list = dynamic_cast(list_of_values.ptr())) { for (auto& entry : static_cast>&>(list->values())) - result.append(AST::create(argument.position(), entry)); + result.append(AST::make_ref_counted(argument.position(), entry)); } else { auto values = list_of_values->resolve_as_list(this); for (auto& entry : values) - result.append(AST::create(argument.position(), entry)); + result.append(AST::make_ref_counted(argument.position(), entry)); } } } - return AST::create(invoking_node.position(), move(result)); + return AST::make_ref_counted(invoking_node.position(), move(result)); } RefPtr Shell::run_immediate_function(StringView str, AST::ImmediateExpression& invoking_node, const NonnullRefPtrVector& arguments)