mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
AK: Rename create<T> => make_ref_counted<T>
And also try_create<T> => try_make_ref_counted<T>. A global "create" was a bit much. The new name matches make<T> better, which we've used for making single-owner objects since forever.
This commit is contained in:
parent
43a800a838
commit
eaf88cc78a
Notes:
sideshowbarker
2024-07-18 04:50:41 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/eaf88cc78a3
17 changed files with 137 additions and 137 deletions
|
@ -333,14 +333,14 @@ inline void swap(NonnullRefPtr<T>& a, NonnullRefPtr<U>& b)
|
|||
}
|
||||
|
||||
template<typename T, class... Args>
|
||||
requires(IsConstructible<T, Args...>) inline NonnullRefPtr<T> create(Args&&... args)
|
||||
requires(IsConstructible<T, Args...>) inline NonnullRefPtr<T> make_ref_counted(Args&&... args)
|
||||
{
|
||||
return NonnullRefPtr<T>(NonnullRefPtr<T>::Adopt, *new T(forward<Args>(args)...));
|
||||
}
|
||||
|
||||
// FIXME: Remove once P0960R3 is available in Clang.
|
||||
template<typename T, class... Args>
|
||||
inline NonnullRefPtr<T> create(Args&&... args)
|
||||
inline NonnullRefPtr<T> make_ref_counted(Args&&... args)
|
||||
{
|
||||
return NonnullRefPtr<T>(NonnullRefPtr<T>::Adopt, *new T { forward<Args>(args)... });
|
||||
}
|
||||
|
@ -355,5 +355,5 @@ struct Traits<NonnullRefPtr<T>> : public GenericTraits<NonnullRefPtr<T>> {
|
|||
};
|
||||
|
||||
using AK::adopt_ref;
|
||||
using AK::create;
|
||||
using AK::make_ref_counted;
|
||||
using AK::NonnullRefPtr;
|
||||
|
|
|
@ -484,14 +484,14 @@ inline RefPtr<T> adopt_ref_if_nonnull(T* object)
|
|||
}
|
||||
|
||||
template<typename T, class... Args>
|
||||
requires(IsConstructible<T, Args...>) inline RefPtr<T> try_create(Args&&... args)
|
||||
requires(IsConstructible<T, Args...>) inline RefPtr<T> try_make_ref_counted(Args&&... args)
|
||||
{
|
||||
return adopt_ref_if_nonnull(new (nothrow) T(forward<Args>(args)...));
|
||||
}
|
||||
|
||||
// FIXME: Remove once P0960R3 is available in Clang.
|
||||
template<typename T, class... Args>
|
||||
inline RefPtr<T> try_create(Args&&... args)
|
||||
inline RefPtr<T> try_make_ref_counted(Args&&... args)
|
||||
{
|
||||
return adopt_ref_if_nonnull(new (nothrow) T { forward<Args>(args)... });
|
||||
}
|
||||
|
@ -512,7 +512,7 @@ inline Kernel::KResultOr<NonnullRefPtr<T>> 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;
|
||||
|
|
|
@ -22,7 +22,7 @@ KResultOr<NonnullRefPtr<Device>> Device::try_create(USBController const& control
|
|||
if (pipe_or_error.is_error())
|
||||
return pipe_or_error.error();
|
||||
|
||||
auto device = AK::try_create<Device>(controller, port, speed, pipe_or_error.release_value());
|
||||
auto device = try_make_ref_counted<Device>(controller, port, speed, pipe_or_error.release_value());
|
||||
if (!device)
|
||||
return ENOMEM;
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ KResultOr<NonnullRefPtr<Hub>> Hub::try_create_root_hub(NonnullRefPtr<USBControll
|
|||
if (pipe_or_error.is_error())
|
||||
return pipe_or_error.error();
|
||||
|
||||
auto hub = AK::try_create<Hub>(controller, device_speed, pipe_or_error.release_value());
|
||||
auto hub = try_make_ref_counted<Hub>(controller, device_speed, pipe_or_error.release_value());
|
||||
if (!hub)
|
||||
return ENOMEM;
|
||||
|
||||
|
@ -34,7 +34,7 @@ KResultOr<NonnullRefPtr<Hub>> Hub::try_create_from_device(Device const& device)
|
|||
if (pipe_or_error.is_error())
|
||||
return pipe_or_error.error();
|
||||
|
||||
auto hub = AK::try_create<Hub>(device, pipe_or_error.release_value());
|
||||
auto hub = try_make_ref_counted<Hub>(device, pipe_or_error.release_value());
|
||||
if (!hub)
|
||||
return ENOMEM;
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ RefPtr<Transfer> Transfer::try_create(Pipe& pipe, u16 len)
|
|||
if (!data_buffer)
|
||||
return {};
|
||||
|
||||
return AK::try_create<Transfer>(pipe, len, data_buffer.release_nonnull());
|
||||
return try_make_ref_counted<Transfer>(pipe, len, data_buffer.release_nonnull());
|
||||
}
|
||||
|
||||
Transfer::Transfer(Pipe& pipe, u16 len, NonnullOwnPtr<Memory::Region> data_buffer)
|
||||
|
|
|
@ -48,7 +48,7 @@ KResultOr<NonnullRefPtr<VMObject>> 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<SharedCommittedCowPages>(committed_pages.release_value());
|
||||
auto new_shared_committed_cow_pages = try_make_ref_counted<SharedCommittedCowPages>(committed_pages.release_value());
|
||||
|
||||
if (!new_shared_committed_cow_pages)
|
||||
return ENOMEM;
|
||||
|
|
|
@ -44,7 +44,7 @@ KResultOr<NonnullRefPtr<Thread>> Thread::try_create(NonnullRefPtr<Process> proce
|
|||
return ENOMEM;
|
||||
kernel_stack_region->set_stack(true);
|
||||
|
||||
auto block_timer = AK::try_create<Timer>();
|
||||
auto block_timer = try_make_ref_counted<Timer>();
|
||||
if (!block_timer)
|
||||
return ENOMEM;
|
||||
|
||||
|
|
|
@ -15,8 +15,8 @@
|
|||
|
||||
Track::Track(const u32& time)
|
||||
: m_time(time)
|
||||
, m_temporary_transport(create<LibDSP::Transport>(120, 4))
|
||||
, m_delay(create<LibDSP::Effects::Delay>(m_temporary_transport))
|
||||
, m_temporary_transport(make_ref_counted<LibDSP::Transport>(120, 4))
|
||||
, m_delay(make_ref_counted<LibDSP::Effects::Delay>(m_temporary_transport))
|
||||
{
|
||||
set_volume(volume_max);
|
||||
set_sustain_impl(1000);
|
||||
|
|
|
@ -27,7 +27,7 @@ public:
|
|||
|
||||
static NonnullRefPtr<Guide> construct(Orientation orientation, float offset)
|
||||
{
|
||||
return create<Guide>(orientation, offset);
|
||||
return make_ref_counted<Guide>(orientation, offset);
|
||||
};
|
||||
|
||||
Orientation orientation() const { return m_orientation; }
|
||||
|
|
|
@ -64,9 +64,9 @@ void GuideTool::on_mousedown(Layer*, MouseEvent& event)
|
|||
|
||||
RefPtr<Guide> 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>(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>(Guide::Orientation::Horizontal, image_event.position().y());
|
||||
}
|
||||
|
||||
if (new_guide) {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -44,7 +44,7 @@ public:
|
|||
if (m_mask & Let)
|
||||
m_parser.m_state.let_scopes.append(NonnullRefPtrVector<VariableDeclaration>());
|
||||
|
||||
m_parser.m_state.current_scope = create<Parser::Scope>(scope_type, m_parser.m_state.current_scope);
|
||||
m_parser.m_state.current_scope = make_ref_counted<Parser::Scope>(scope_type, m_parser.m_state.current_scope);
|
||||
}
|
||||
|
||||
~ScopePusher()
|
||||
|
|
|
@ -707,7 +707,7 @@ NonnullRefPtr<StyleRule> Parser::consume_an_at_rule(TokenStream<T>& tokens)
|
|||
auto& name_ident = tokens.next_token();
|
||||
VERIFY(name_ident.is(Token::Type::AtKeyword));
|
||||
|
||||
NonnullRefPtr<StyleRule> rule = create<StyleRule>(StyleRule::Type::At);
|
||||
auto rule = make_ref_counted<StyleRule>(StyleRule::Type::At);
|
||||
rule->m_name = ((Token)name_ident).at_keyword();
|
||||
|
||||
for (;;) {
|
||||
|
@ -744,7 +744,7 @@ RefPtr<StyleRule> Parser::consume_a_qualified_rule(TokenStream<T>& tokens)
|
|||
{
|
||||
dbgln_if(CSS_PARSER_DEBUG, "Parser::consume_a_qualified_rule");
|
||||
|
||||
NonnullRefPtr<StyleRule> rule = create<StyleRule>(StyleRule::Type::Qualified);
|
||||
auto rule = make_ref_counted<StyleRule>(StyleRule::Type::Qualified);
|
||||
|
||||
for (;;) {
|
||||
auto& token = tokens.next_token();
|
||||
|
@ -810,7 +810,7 @@ NonnullRefPtr<StyleBlockRule> Parser::consume_a_simple_block(TokenStream<T>& tok
|
|||
|
||||
auto ending_token = ((Token)tokens.current_token()).mirror_variant();
|
||||
|
||||
NonnullRefPtr<StyleBlockRule> block = create<StyleBlockRule>();
|
||||
auto block = make_ref_counted<StyleBlockRule>();
|
||||
block->m_token = tokens.current_token();
|
||||
|
||||
for (;;) {
|
||||
|
@ -843,7 +843,7 @@ NonnullRefPtr<StyleFunctionRule> Parser::consume_a_function(TokenStream<T>& toke
|
|||
|
||||
auto name_ident = tokens.current_token();
|
||||
VERIFY(name_ident.is(Token::Type::Function));
|
||||
NonnullRefPtr<StyleFunctionRule> function = create<StyleFunctionRule>(((Token)name_ident).m_value.to_string());
|
||||
auto function = make_ref_counted<StyleFunctionRule>(((Token)name_ident).m_value.to_string());
|
||||
|
||||
for (;;) {
|
||||
auto& token = tokens.next_token();
|
||||
|
|
|
@ -286,7 +286,7 @@ void Node::for_each_entry(RefPtr<Shell> shell, Function<IterationDecision(Nonnul
|
|||
|
||||
auto list = value->resolve_as_list(shell);
|
||||
for (auto& element : list) {
|
||||
if (callback(create<StringValue>(move(element))) == IterationDecision::Break)
|
||||
if (callback(make_ref_counted<StringValue>(move(element))) == IterationDecision::Break)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -390,7 +390,7 @@ RefPtr<Value> And::run(RefPtr<Shell> shell)
|
|||
{
|
||||
auto commands = m_left->to_lazy_evaluated_commands(shell);
|
||||
commands.last().next_chain.append(NodeWithAction { *m_right, NodeWithAction::And });
|
||||
return create<CommandSequenceValue>(move(commands));
|
||||
return make_ref_counted<CommandSequenceValue>(move(commands));
|
||||
}
|
||||
|
||||
void And::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata)
|
||||
|
@ -444,7 +444,7 @@ RefPtr<Value> ListConcatenate::run(RefPtr<Shell> shell)
|
|||
|
||||
for (auto& element : m_list) {
|
||||
if (!result) {
|
||||
result = create<ListValue>({ element->run(shell)->resolve_without_cast(shell) });
|
||||
result = make_ref_counted<ListValue>({ element->run(shell)->resolve_without_cast(shell) });
|
||||
continue;
|
||||
}
|
||||
auto element_value = element->run(shell)->resolve_without_cast(shell);
|
||||
|
@ -455,9 +455,9 @@ RefPtr<Value> ListConcatenate::run(RefPtr<Shell> shell)
|
|||
if (joined_commands.size() == 1) {
|
||||
auto& command = joined_commands[0];
|
||||
command.position = position();
|
||||
result = create<CommandValue>(command);
|
||||
result = make_ref_counted<CommandValue>(command);
|
||||
} else {
|
||||
result = create<CommandSequenceValue>(move(joined_commands));
|
||||
result = make_ref_counted<CommandSequenceValue>(move(joined_commands));
|
||||
}
|
||||
} else {
|
||||
NonnullRefPtrVector<Value> values;
|
||||
|
@ -466,16 +466,16 @@ RefPtr<Value> ListConcatenate::run(RefPtr<Shell> shell)
|
|||
values.extend(static_cast<ListValue*>(result.ptr())->values());
|
||||
} else {
|
||||
for (auto& result : result->resolve_as_list(shell))
|
||||
values.append(create<StringValue>(result));
|
||||
values.append(make_ref_counted<StringValue>(result));
|
||||
}
|
||||
|
||||
values.append(element_value);
|
||||
|
||||
result = create<ListValue>(move(values));
|
||||
result = make_ref_counted<ListValue>(move(values));
|
||||
}
|
||||
}
|
||||
if (!result)
|
||||
return create<ListValue>({});
|
||||
return make_ref_counted<ListValue>({});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -554,7 +554,7 @@ RefPtr<Value> Background::run(RefPtr<Shell> shell)
|
|||
for (auto& command : commands)
|
||||
command.should_wait = false;
|
||||
|
||||
return create<CommandSequenceValue>(move(commands));
|
||||
return make_ref_counted<CommandSequenceValue>(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<Value> BarewordLiteral::run(RefPtr<Shell>)
|
||||
{
|
||||
return create<StringValue>(m_text);
|
||||
return make_ref_counted<StringValue>(m_text);
|
||||
}
|
||||
|
||||
void BarewordLiteral::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata)
|
||||
|
@ -651,7 +651,7 @@ RefPtr<Value> BraceExpansion::run(RefPtr<Shell> shell)
|
|||
values.append(value.release_nonnull());
|
||||
}
|
||||
|
||||
return create<ListValue>(move(values));
|
||||
return make_ref_counted<ListValue>(move(values));
|
||||
}
|
||||
|
||||
HitTestResult BraceExpansion::hit_test_position(size_t offset) const
|
||||
|
@ -708,7 +708,7 @@ RefPtr<Value> CastToCommand::run(RefPtr<Shell> shell)
|
|||
return value;
|
||||
|
||||
auto argv = value->resolve_as_list(shell);
|
||||
return create<CommandValue>(move(argv), position());
|
||||
return make_ref_counted<CommandValue>(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<Value> CastToList::run(RefPtr<Shell> shell)
|
||||
{
|
||||
if (!m_inner)
|
||||
return create<ListValue>({});
|
||||
return make_ref_counted<ListValue>({});
|
||||
|
||||
auto inner_value = m_inner->run(shell)->resolve_without_cast(shell);
|
||||
|
||||
|
@ -778,9 +778,9 @@ RefPtr<Value> CastToList::run(RefPtr<Shell> shell)
|
|||
auto values = inner_value->resolve_as_list(shell);
|
||||
NonnullRefPtrVector<Value> cast_values;
|
||||
for (auto& value : values)
|
||||
cast_values.append(create<StringValue>(value));
|
||||
cast_values.append(make_ref_counted<StringValue>(value));
|
||||
|
||||
return create<ListValue>(cast_values);
|
||||
return make_ref_counted<ListValue>(cast_values);
|
||||
}
|
||||
|
||||
void CastToList::for_each_entry(RefPtr<Shell> shell, Function<IterationDecision(NonnullRefPtr<Value>)> callback)
|
||||
|
@ -831,7 +831,7 @@ RefPtr<Value> CloseFdRedirection::run(RefPtr<Shell>)
|
|||
Command command;
|
||||
command.position = position();
|
||||
command.redirections.append(adopt_ref(*new CloseRedirection(m_fd)));
|
||||
return create<CommandValue>(move(command));
|
||||
return make_ref_counted<CommandValue>(move(command));
|
||||
}
|
||||
|
||||
void CloseFdRedirection::highlight_in_editor(Line::Editor& editor, Shell&, HighlightMetadata)
|
||||
|
@ -858,7 +858,7 @@ void CommandLiteral::dump(int level) const
|
|||
|
||||
RefPtr<Value> CommandLiteral::run(RefPtr<Shell>)
|
||||
{
|
||||
return create<CommandValue>(m_command);
|
||||
return make_ref_counted<CommandValue>(m_command);
|
||||
}
|
||||
|
||||
CommandLiteral::CommandLiteral(Position position, Command command)
|
||||
|
@ -879,7 +879,7 @@ void Comment::dump(int level) const
|
|||
|
||||
RefPtr<Value> Comment::run(RefPtr<Shell>)
|
||||
{
|
||||
return create<ListValue>({});
|
||||
return make_ref_counted<ListValue>({});
|
||||
}
|
||||
|
||||
void Comment::highlight_in_editor(Line::Editor& editor, Shell&, HighlightMetadata)
|
||||
|
@ -911,7 +911,7 @@ RefPtr<Value> ContinuationControl::run(RefPtr<Shell> shell)
|
|||
shell->raise_error(Shell::ShellError::InternalControlFlowContinue, {}, position());
|
||||
else
|
||||
VERIFY_NOT_REACHED();
|
||||
return create<ListValue>({});
|
||||
return make_ref_counted<ListValue>({});
|
||||
}
|
||||
|
||||
void ContinuationControl::highlight_in_editor(Line::Editor& editor, Shell&, HighlightMetadata)
|
||||
|
@ -932,7 +932,7 @@ RefPtr<Value> DoubleQuotedString::run(RefPtr<Shell> shell)
|
|||
|
||||
builder.join("", values);
|
||||
|
||||
return create<StringValue>(builder.to_string());
|
||||
return make_ref_counted<StringValue>(builder.to_string());
|
||||
}
|
||||
|
||||
void DoubleQuotedString::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata)
|
||||
|
@ -977,12 +977,12 @@ RefPtr<Value> DynamicEvaluate::run(RefPtr<Shell> shell)
|
|||
if (result->is_string()) {
|
||||
auto name_part = result->resolve_as_list(shell);
|
||||
VERIFY(name_part.size() == 1);
|
||||
return create<SimpleVariableValue>(name_part[0]);
|
||||
return make_ref_counted<SimpleVariableValue>(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<CommandValue>(move(list), position());
|
||||
return make_ref_counted<CommandValue>(move(list), position());
|
||||
}
|
||||
|
||||
void DynamicEvaluate::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata)
|
||||
|
@ -1019,7 +1019,7 @@ RefPtr<Value> Fd2FdRedirection::run(RefPtr<Shell>)
|
|||
Command command;
|
||||
command.position = position();
|
||||
command.redirections.append(FdRedirection::create(m_new_fd, m_old_fd, Rewiring::Close::None));
|
||||
return create<CommandValue>(move(command));
|
||||
return make_ref_counted<CommandValue>(move(command));
|
||||
}
|
||||
|
||||
void Fd2FdRedirection::highlight_in_editor(Line::Editor& editor, Shell&, HighlightMetadata)
|
||||
|
@ -1061,7 +1061,7 @@ RefPtr<Value> FunctionDeclaration::run(RefPtr<Shell> shell)
|
|||
|
||||
shell->define_function(m_name.name, move(args), m_block);
|
||||
|
||||
return create<ListValue>({});
|
||||
return make_ref_counted<ListValue>({});
|
||||
}
|
||||
|
||||
void FunctionDeclaration::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata)
|
||||
|
@ -1147,7 +1147,7 @@ void ForLoop::dump(int level) const
|
|||
RefPtr<Value> ForLoop::run(RefPtr<Shell> shell)
|
||||
{
|
||||
if (!m_block)
|
||||
return create<ListValue>({});
|
||||
return make_ref_counted<ListValue>({});
|
||||
|
||||
size_t consecutive_interruptions = 0;
|
||||
auto run = [&](auto& block_value) {
|
||||
|
@ -1197,7 +1197,7 @@ RefPtr<Value> ForLoop::run(RefPtr<Shell> shell)
|
|||
shell->set_local_variable(variable_name, value, true);
|
||||
|
||||
if (index_name.has_value())
|
||||
shell->set_local_variable(index_name.value(), create<AST::StringValue>(String::number(i)), true);
|
||||
shell->set_local_variable(index_name.value(), make_ref_counted<AST::StringValue>(String::number(i)), true);
|
||||
|
||||
++i;
|
||||
|
||||
|
@ -1217,7 +1217,7 @@ RefPtr<Value> ForLoop::run(RefPtr<Shell> shell)
|
|||
}
|
||||
}
|
||||
|
||||
return create<ListValue>({});
|
||||
return make_ref_counted<ListValue>({});
|
||||
}
|
||||
|
||||
void ForLoop::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata)
|
||||
|
@ -1286,7 +1286,7 @@ void Glob::dump(int level) const
|
|||
|
||||
RefPtr<Value> Glob::run(RefPtr<Shell>)
|
||||
{
|
||||
return create<GlobValue>(m_text, position());
|
||||
return make_ref_counted<GlobValue>(m_text, position());
|
||||
}
|
||||
|
||||
void Glob::highlight_in_editor(Line::Editor& editor, Shell&, HighlightMetadata metadata)
|
||||
|
@ -1342,7 +1342,7 @@ RefPtr<Value> Heredoc::run(RefPtr<Shell> shell)
|
|||
builder.append('\n');
|
||||
}
|
||||
|
||||
return create<StringValue>(builder.to_string());
|
||||
return make_ref_counted<StringValue>(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<Value> HistoryEvent::run(RefPtr<Shell> shell)
|
||||
{
|
||||
if (!shell)
|
||||
return create<AST::ListValue>({});
|
||||
return make_ref_counted<AST::ListValue>({});
|
||||
|
||||
auto editor = shell->editor();
|
||||
if (!editor) {
|
||||
shell->raise_error(Shell::ShellError::EvaluatedSyntaxError, "No history available!", position());
|
||||
return create<AST::ListValue>({});
|
||||
return make_ref_counted<AST::ListValue>({});
|
||||
}
|
||||
auto& history = editor->history();
|
||||
|
||||
|
@ -1450,14 +1450,14 @@ RefPtr<Value> HistoryEvent::run(RefPtr<Shell> 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<AST::ListValue>({});
|
||||
return make_ref_counted<AST::ListValue>({});
|
||||
}
|
||||
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<AST::ListValue>({});
|
||||
return make_ref_counted<AST::ListValue>({});
|
||||
}
|
||||
resolved_history = history[history.size() - m_selector.event.index - 1].entry;
|
||||
break;
|
||||
|
@ -1465,7 +1465,7 @@ RefPtr<Value> HistoryEvent::run(RefPtr<Shell> 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<AST::ListValue>({});
|
||||
return make_ref_counted<AST::ListValue>({});
|
||||
}
|
||||
resolved_history = it->entry;
|
||||
break;
|
||||
|
@ -1474,7 +1474,7 @@ RefPtr<Value> HistoryEvent::run(RefPtr<Shell> 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<AST::ListValue>({});
|
||||
return make_ref_counted<AST::ListValue>({});
|
||||
}
|
||||
resolved_history = it->entry;
|
||||
break;
|
||||
|
@ -1491,23 +1491,23 @@ RefPtr<Value> HistoryEvent::run(RefPtr<Shell> 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<AST::ListValue>({});
|
||||
return make_ref_counted<AST::ListValue>({});
|
||||
}
|
||||
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<AST::ListValue>({});
|
||||
return make_ref_counted<AST::ListValue>({});
|
||||
}
|
||||
|
||||
decltype(nodes) resolved_nodes;
|
||||
resolved_nodes.append(nodes.data() + start_index, end_index - start_index + 1);
|
||||
NonnullRefPtr<AST::Node> list = create<AST::ListConcatenate>(position(), move(resolved_nodes));
|
||||
NonnullRefPtr<AST::Node> list = make_ref_counted<AST::ListConcatenate>(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<AST::ListValue>({});
|
||||
return make_ref_counted<AST::ListValue>({});
|
||||
}
|
||||
return nodes[index].run(shell);
|
||||
}
|
||||
|
@ -1583,7 +1583,7 @@ void Execute::for_each_entry(RefPtr<Shell> shell, Function<IterationDecision(Non
|
|||
VERIFY(rc);
|
||||
|
||||
if (shell->options.inline_exec_keep_empty_segments)
|
||||
if (callback(create<StringValue>("")) == IterationDecision::Break) {
|
||||
if (callback(make_ref_counted<StringValue>("")) == IterationDecision::Break) {
|
||||
loop.quit(Break);
|
||||
notifier->set_enabled(false);
|
||||
return Break;
|
||||
|
@ -1594,7 +1594,7 @@ void Execute::for_each_entry(RefPtr<Shell> shell, Function<IterationDecision(Non
|
|||
VERIFY(rc);
|
||||
|
||||
auto str = StringView(entry.data(), entry.size() - ifs.length());
|
||||
if (callback(create<StringValue>(str)) == IterationDecision::Break) {
|
||||
if (callback(make_ref_counted<StringValue>(str)) == IterationDecision::Break) {
|
||||
loop.quit(Break);
|
||||
notifier->set_enabled(false);
|
||||
return Break;
|
||||
|
@ -1678,7 +1678,7 @@ void Execute::for_each_entry(RefPtr<Shell> shell, Function<IterationDecision(Non
|
|||
auto entry = ByteBuffer::create_uninitialized(stream.size());
|
||||
auto rc = stream.read_or_error(entry);
|
||||
VERIFY(rc);
|
||||
callback(create<StringValue>(String::copy(entry)));
|
||||
callback(make_ref_counted<StringValue>(String::copy(entry)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1688,7 +1688,7 @@ void Execute::for_each_entry(RefPtr<Shell> shell, Function<IterationDecision(Non
|
|||
auto jobs = shell->run_commands(commands);
|
||||
|
||||
if (!jobs.is_empty())
|
||||
callback(create<JobValue>(&jobs.last()));
|
||||
callback(make_ref_counted<JobValue>(&jobs.last()));
|
||||
}
|
||||
|
||||
RefPtr<Value> Execute::run(RefPtr<Shell> shell)
|
||||
|
@ -1705,7 +1705,7 @@ RefPtr<Value> Execute::run(RefPtr<Shell> shell)
|
|||
if (values.size() == 1 && values.first().is_job())
|
||||
return values.first();
|
||||
|
||||
return create<ListValue>(move(values));
|
||||
return make_ref_counted<ListValue>(move(values));
|
||||
}
|
||||
|
||||
void Execute::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata)
|
||||
|
@ -1789,7 +1789,7 @@ RefPtr<Value> IfCond::run(RefPtr<Shell> shell)
|
|||
return m_false_branch->run(shell);
|
||||
}
|
||||
|
||||
return create<ListValue>({});
|
||||
return make_ref_counted<ListValue>({});
|
||||
}
|
||||
|
||||
void IfCond::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata)
|
||||
|
@ -1839,7 +1839,7 @@ IfCond::IfCond(Position position, Optional<Position> 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<AST::Execute>(m_condition->position(), m_condition);
|
||||
m_condition = make_ref_counted<AST::Execute>(m_condition->position(), m_condition);
|
||||
|
||||
if (m_true_branch) {
|
||||
auto true_branch = m_true_branch.release_nonnull();
|
||||
|
@ -1878,7 +1878,7 @@ RefPtr<Value> ImmediateExpression::run(RefPtr<Shell> shell)
|
|||
if (node)
|
||||
return node->run(shell);
|
||||
|
||||
return create<ListValue>({});
|
||||
return make_ref_counted<ListValue>({});
|
||||
}
|
||||
|
||||
void ImmediateExpression::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata)
|
||||
|
@ -1963,7 +1963,7 @@ RefPtr<Value> Join::run(RefPtr<Shell> shell)
|
|||
auto left = m_left->to_lazy_evaluated_commands(shell);
|
||||
auto right = m_right->to_lazy_evaluated_commands(shell);
|
||||
|
||||
return create<CommandSequenceValue>(join_commands(move(left), move(right)));
|
||||
return make_ref_counted<CommandSequenceValue>(join_commands(move(left), move(right)));
|
||||
}
|
||||
|
||||
void Join::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata)
|
||||
|
@ -2091,20 +2091,20 @@ RefPtr<Value> MatchExpr::run(RefPtr<Shell> shell)
|
|||
size_t i = 0;
|
||||
for (auto& name : entry.match_names.value()) {
|
||||
if (spans.size() > i)
|
||||
shell->set_local_variable(name, create<AST::StringValue>(spans[i]), true);
|
||||
shell->set_local_variable(name, make_ref_counted<AST::StringValue>(spans[i]), true);
|
||||
++i;
|
||||
}
|
||||
}
|
||||
return entry.body->run(shell);
|
||||
} else {
|
||||
return create<AST::ListValue>({});
|
||||
return make_ref_counted<AST::ListValue>({});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
shell->raise_error(Shell::ShellError::EvaluatedSyntaxError, "Non-exhaustive match rules!", position());
|
||||
return create<AST::ListValue>({});
|
||||
return make_ref_counted<AST::ListValue>({});
|
||||
}
|
||||
|
||||
void MatchExpr::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata)
|
||||
|
@ -2186,7 +2186,7 @@ RefPtr<Value> Or::run(RefPtr<Shell> shell)
|
|||
{
|
||||
auto commands = m_left->to_lazy_evaluated_commands(shell);
|
||||
commands.last().next_chain.empend(*m_right, NodeWithAction::Or);
|
||||
return create<CommandSequenceValue>(move(commands));
|
||||
return make_ref_counted<CommandSequenceValue>(move(commands));
|
||||
}
|
||||
|
||||
void Or::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata)
|
||||
|
@ -2270,7 +2270,7 @@ RefPtr<Value> Pipe::run(RefPtr<Shell> shell)
|
|||
if (first_in_right.pipeline) {
|
||||
last_in_left.pipeline = first_in_right.pipeline;
|
||||
} else {
|
||||
auto pipeline = create<Pipeline>();
|
||||
auto pipeline = make_ref_counted<Pipeline>();
|
||||
last_in_left.pipeline = pipeline;
|
||||
first_in_right.pipeline = pipeline;
|
||||
}
|
||||
|
@ -2281,7 +2281,7 @@ RefPtr<Value> Pipe::run(RefPtr<Shell> shell)
|
|||
commands.append(first_in_right);
|
||||
commands.extend(right);
|
||||
|
||||
return create<CommandSequenceValue>(move(commands));
|
||||
return make_ref_counted<CommandSequenceValue>(move(commands));
|
||||
}
|
||||
|
||||
void Pipe::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata)
|
||||
|
@ -2402,12 +2402,12 @@ RefPtr<Value> Range::run(RefPtr<Shell> 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<StringValue>(builder.to_string()));
|
||||
values.append(make_ref_counted<StringValue>(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<StringValue>(builder.to_string()));
|
||||
values.append(make_ref_counted<StringValue>(builder.to_string()));
|
||||
} else {
|
||||
// Could be two numbers?
|
||||
auto start_int = start_str.to_int();
|
||||
|
@ -2417,9 +2417,9 @@ RefPtr<Value> Range::run(RefPtr<Shell> shell)
|
|||
auto end = end_int.value();
|
||||
auto step = start > end ? -1 : 1;
|
||||
for (int value = start; value != end; value += step)
|
||||
values.append(create<StringValue>(String::number(value)));
|
||||
values.append(make_ref_counted<StringValue>(String::number(value)));
|
||||
// Append the range end too, most shells treat this as inclusive.
|
||||
values.append(create<StringValue>(String::number(end)));
|
||||
values.append(make_ref_counted<StringValue>(String::number(end)));
|
||||
} else {
|
||||
goto yield_start_end;
|
||||
}
|
||||
|
@ -2428,8 +2428,8 @@ RefPtr<Value> Range::run(RefPtr<Shell> 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<StringValue>(move(start_str)));
|
||||
values.append(create<StringValue>(move(end_str)));
|
||||
values.append(make_ref_counted<StringValue>(move(start_str)));
|
||||
values.append(make_ref_counted<StringValue>(move(end_str)));
|
||||
}
|
||||
|
||||
return values;
|
||||
|
@ -2442,9 +2442,9 @@ RefPtr<Value> Range::run(RefPtr<Shell> shell)
|
|||
auto start_value = m_start->run(shell);
|
||||
auto end_value = m_end->run(shell);
|
||||
if (!start_value || !end_value)
|
||||
return create<ListValue>({});
|
||||
return make_ref_counted<ListValue>({});
|
||||
|
||||
return create<ListValue>(interpolate(*start_value, *end_value, shell));
|
||||
return make_ref_counted<ListValue>(interpolate(*start_value, *end_value, shell));
|
||||
}
|
||||
|
||||
void Range::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata)
|
||||
|
@ -2503,7 +2503,7 @@ RefPtr<Value> ReadRedirection::run(RefPtr<Shell> shell)
|
|||
builder.join(" ", path_segments);
|
||||
|
||||
command.redirections.append(PathRedirection::create(builder.to_string(), m_fd, PathRedirection::Read));
|
||||
return create<CommandValue>(move(command));
|
||||
return make_ref_counted<CommandValue>(move(command));
|
||||
}
|
||||
|
||||
ReadRedirection::ReadRedirection(Position position, int fd, NonnullRefPtr<Node> path)
|
||||
|
@ -2530,7 +2530,7 @@ RefPtr<Value> ReadWriteRedirection::run(RefPtr<Shell> shell)
|
|||
builder.join(" ", path_segments);
|
||||
|
||||
command.redirections.append(PathRedirection::create(builder.to_string(), m_fd, PathRedirection::ReadWrite));
|
||||
return create<CommandValue>(move(command));
|
||||
return make_ref_counted<CommandValue>(move(command));
|
||||
}
|
||||
|
||||
ReadWriteRedirection::ReadWriteRedirection(Position position, int fd, NonnullRefPtr<Node> path)
|
||||
|
@ -2569,7 +2569,7 @@ RefPtr<Value> Sequence::run(RefPtr<Shell> shell)
|
|||
}
|
||||
}
|
||||
|
||||
return create<CommandSequenceValue>(move(all_commands));
|
||||
return make_ref_counted<CommandSequenceValue>(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<Value> Subshell::run(RefPtr<Shell> shell)
|
||||
{
|
||||
if (!m_block)
|
||||
return create<ListValue>({});
|
||||
return make_ref_counted<ListValue>({});
|
||||
|
||||
return create<AST::CommandSequenceValue>(m_block->to_lazy_evaluated_commands(shell));
|
||||
return make_ref_counted<AST::CommandSequenceValue>(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<Value> SimpleVariable::run(RefPtr<Shell>)
|
||||
{
|
||||
NonnullRefPtr<Value> value = create<SimpleVariableValue>(m_name);
|
||||
NonnullRefPtr<Value> value = make_ref_counted<SimpleVariableValue>(m_name);
|
||||
if (m_slice)
|
||||
value = value->with_slices(*m_slice);
|
||||
return value;
|
||||
|
@ -2769,7 +2769,7 @@ void SpecialVariable::dump(int level) const
|
|||
|
||||
RefPtr<Value> SpecialVariable::run(RefPtr<Shell>)
|
||||
{
|
||||
NonnullRefPtr<Value> value = create<SpecialVariableValue>(m_name);
|
||||
NonnullRefPtr<Value> value = make_ref_counted<SpecialVariableValue>(m_name);
|
||||
if (m_slice)
|
||||
value = value->with_slices(*m_slice);
|
||||
return value;
|
||||
|
@ -2829,12 +2829,12 @@ RefPtr<Value> Juxtaposition::run(RefPtr<Shell> shell)
|
|||
builder.append(left[0]);
|
||||
builder.append(right[0]);
|
||||
|
||||
return create<StringValue>(builder.to_string());
|
||||
return make_ref_counted<StringValue>(builder.to_string());
|
||||
}
|
||||
|
||||
// Otherwise, treat them as lists and create a list product.
|
||||
if (left.is_empty() || right.is_empty())
|
||||
return create<ListValue>({});
|
||||
return make_ref_counted<ListValue>({});
|
||||
|
||||
Vector<String> result;
|
||||
result.ensure_capacity(left.size() * right.size());
|
||||
|
@ -2849,7 +2849,7 @@ RefPtr<Value> Juxtaposition::run(RefPtr<Shell> shell)
|
|||
}
|
||||
}
|
||||
|
||||
return create<ListValue>(move(result));
|
||||
return make_ref_counted<ListValue>(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<Value> StringLiteral::run(RefPtr<Shell>)
|
||||
{
|
||||
return create<StringValue>(m_text);
|
||||
return make_ref_counted<StringValue>(m_text);
|
||||
}
|
||||
|
||||
void StringLiteral::highlight_in_editor(Line::Editor& editor, Shell&, HighlightMetadata metadata)
|
||||
|
@ -2980,7 +2980,7 @@ RefPtr<Value> StringPartCompose::run(RefPtr<Shell> shell)
|
|||
builder.join(" ", left);
|
||||
builder.join(" ", right);
|
||||
|
||||
return create<StringValue>(builder.to_string());
|
||||
return make_ref_counted<StringValue>(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<Value> SyntaxError::run(RefPtr<Shell> shell)
|
||||
{
|
||||
shell->raise_error(Shell::ShellError::EvaluatedSyntaxError, m_syntax_error_text, position());
|
||||
return create<StringValue>("");
|
||||
return make_ref_counted<StringValue>("");
|
||||
}
|
||||
|
||||
void SyntaxError::highlight_in_editor(Line::Editor& editor, Shell&, HighlightMetadata)
|
||||
|
@ -3076,7 +3076,7 @@ void Tilde::dump(int level) const
|
|||
|
||||
RefPtr<Value> Tilde::run(RefPtr<Shell>)
|
||||
{
|
||||
return create<TildeValue>(m_username);
|
||||
return make_ref_counted<TildeValue>(m_username);
|
||||
}
|
||||
|
||||
void Tilde::highlight_in_editor(Line::Editor&, Shell&, HighlightMetadata)
|
||||
|
@ -3141,7 +3141,7 @@ RefPtr<Value> WriteAppendRedirection::run(RefPtr<Shell> shell)
|
|||
builder.join(" ", path_segments);
|
||||
|
||||
command.redirections.append(PathRedirection::create(builder.to_string(), m_fd, PathRedirection::WriteAppend));
|
||||
return create<CommandValue>(move(command));
|
||||
return make_ref_counted<CommandValue>(move(command));
|
||||
}
|
||||
|
||||
WriteAppendRedirection::WriteAppendRedirection(Position position, int fd, NonnullRefPtr<Node> path)
|
||||
|
@ -3168,7 +3168,7 @@ RefPtr<Value> WriteRedirection::run(RefPtr<Shell> shell)
|
|||
builder.join(" ", path_segments);
|
||||
|
||||
command.redirections.append(PathRedirection::create(builder.to_string(), m_fd, PathRedirection::Write));
|
||||
return create<CommandValue>(move(command));
|
||||
return make_ref_counted<CommandValue>(move(command));
|
||||
}
|
||||
|
||||
WriteRedirection::WriteRedirection(Position position, int fd, NonnullRefPtr<Node> path)
|
||||
|
@ -3200,7 +3200,7 @@ RefPtr<Value> VariableDeclarations::run(RefPtr<Shell> shell)
|
|||
shell->set_local_variable(name, value.release_nonnull());
|
||||
}
|
||||
|
||||
return create<ListValue>({});
|
||||
return make_ref_counted<ListValue>({});
|
||||
}
|
||||
|
||||
void VariableDeclarations::highlight_in_editor(Line::Editor& editor, Shell& shell, HighlightMetadata metadata)
|
||||
|
@ -3297,7 +3297,7 @@ NonnullRefPtr<Value> ListValue::resolve_without_cast(RefPtr<Shell> shell)
|
|||
for (auto& value : m_contained_values)
|
||||
values.append(value.resolve_without_cast(shell));
|
||||
|
||||
NonnullRefPtr<Value> value = create<ListValue>(move(values));
|
||||
NonnullRefPtr<Value> value = make_ref_counted<ListValue>(move(values));
|
||||
if (!m_slices.is_empty())
|
||||
value = value->with_slices(m_slices);
|
||||
return value;
|
||||
|
@ -3357,7 +3357,7 @@ Vector<String> StringValue::resolve_as_list(RefPtr<Shell> shell)
|
|||
NonnullRefPtr<Value> StringValue::resolve_without_cast(RefPtr<Shell> shell)
|
||||
{
|
||||
if (is_list())
|
||||
return create<AST::ListValue>(resolve_as_list(shell)); // No need to reapply the slices.
|
||||
return make_ref_counted<AST::ListValue>(resolve_as_list(shell)); // No need to reapply the slices.
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
|
|
@ -20,10 +20,10 @@
|
|||
|
||||
namespace Shell::AST {
|
||||
|
||||
using AK::create;
|
||||
using AK::make_ref_counted;
|
||||
|
||||
template<typename T>
|
||||
static inline NonnullRefPtr<T> create(std::initializer_list<NonnullRefPtr<Value>> arg)
|
||||
static inline NonnullRefPtr<T> make_ref_counted(std::initializer_list<NonnullRefPtr<Value>> arg)
|
||||
{
|
||||
return adopt_ref(*new T(arg));
|
||||
}
|
||||
|
@ -243,7 +243,7 @@ class CommandValue final : public Value {
|
|||
public:
|
||||
virtual Vector<String> resolve_as_list(RefPtr<Shell>) override;
|
||||
virtual Vector<Command> resolve_as_commands(RefPtr<Shell>) override;
|
||||
virtual NonnullRefPtr<Value> clone() const override { return create<CommandValue>(m_command)->set_slices(m_slices); }
|
||||
virtual NonnullRefPtr<Value> clone() const override { return make_ref_counted<CommandValue>(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<String> resolve_as_list(RefPtr<Shell>) override;
|
||||
virtual Vector<Command> resolve_as_commands(RefPtr<Shell>) override;
|
||||
virtual NonnullRefPtr<Value> clone() const override { return create<CommandSequenceValue>(m_contained_values)->set_slices(m_slices); }
|
||||
virtual NonnullRefPtr<Value> clone() const override { return make_ref_counted<CommandSequenceValue>(m_contained_values)->set_slices(m_slices); }
|
||||
virtual ~CommandSequenceValue();
|
||||
virtual bool is_command() const override { return true; }
|
||||
CommandSequenceValue(Vector<Command> commands)
|
||||
|
@ -280,7 +280,7 @@ class JobValue final : public Value {
|
|||
public:
|
||||
virtual Vector<String> resolve_as_list(RefPtr<Shell>) override { VERIFY_NOT_REACHED(); }
|
||||
virtual Vector<Command> resolve_as_commands(RefPtr<Shell>) override { VERIFY_NOT_REACHED(); }
|
||||
virtual NonnullRefPtr<Value> clone() const override { return create<JobValue>(m_job)->set_slices(m_slices); }
|
||||
virtual NonnullRefPtr<Value> clone() const override { return make_ref_counted<JobValue>(m_job)->set_slices(m_slices); }
|
||||
virtual ~JobValue();
|
||||
virtual bool is_job() const override { return true; }
|
||||
JobValue(RefPtr<Job> job)
|
||||
|
@ -298,7 +298,7 @@ class ListValue final : public Value {
|
|||
public:
|
||||
virtual Vector<String> resolve_as_list(RefPtr<Shell>) override;
|
||||
virtual NonnullRefPtr<Value> resolve_without_cast(RefPtr<Shell>) override;
|
||||
virtual NonnullRefPtr<Value> clone() const override { return create<ListValue>(m_contained_values)->set_slices(m_slices); }
|
||||
virtual NonnullRefPtr<Value> clone() const override { return make_ref_counted<ListValue>(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<String> resolve_as_list(RefPtr<Shell>) override;
|
||||
virtual NonnullRefPtr<Value> clone() const override { return create<StringValue>(m_string, m_split, m_keep_empty)->set_slices(m_slices); }
|
||||
virtual NonnullRefPtr<Value> clone() const override { return make_ref_counted<StringValue>(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<String> resolve_as_list(RefPtr<Shell>) override;
|
||||
virtual NonnullRefPtr<Value> clone() const override { return create<GlobValue>(m_glob, m_generation_position)->set_slices(m_slices); }
|
||||
virtual NonnullRefPtr<Value> clone() const override { return make_ref_counted<GlobValue>(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<String> resolve_as_list(RefPtr<Shell>) override;
|
||||
virtual NonnullRefPtr<Value> resolve_without_cast(RefPtr<Shell>) override;
|
||||
virtual NonnullRefPtr<Value> clone() const override { return create<SimpleVariableValue>(m_name)->set_slices(m_slices); }
|
||||
virtual NonnullRefPtr<Value> clone() const override { return make_ref_counted<SimpleVariableValue>(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<String> resolve_as_list(RefPtr<Shell>) override;
|
||||
virtual NonnullRefPtr<Value> clone() const override { return create<SpecialVariableValue>(m_name)->set_slices(m_slices); }
|
||||
virtual NonnullRefPtr<Value> clone() const override { return make_ref_counted<SpecialVariableValue>(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<String> resolve_as_list(RefPtr<Shell>) override;
|
||||
virtual NonnullRefPtr<Value> clone() const override { return create<TildeValue>(m_username)->set_slices(m_slices); }
|
||||
virtual NonnullRefPtr<Value> clone() const override { return make_ref_counted<TildeValue>(m_username)->set_slices(m_slices); }
|
||||
virtual ~TildeValue();
|
||||
virtual bool is_string() const override { return true; }
|
||||
TildeValue(String name)
|
||||
|
|
|
@ -868,7 +868,7 @@ int Shell::builtin_source(int argc, const char** argv)
|
|||
} };
|
||||
|
||||
if (!args.is_empty())
|
||||
set_local_variable("ARGV", AST::create<AST::ListValue>(move(string_argv)));
|
||||
set_local_variable("ARGV", AST::make_ref_counted<AST::ListValue>(move(string_argv)));
|
||||
|
||||
if (!run_file(file_to_source, true))
|
||||
return 126;
|
||||
|
|
|
@ -67,7 +67,7 @@ RefPtr<AST::Node> Shell::immediate_length_impl(AST::ImmediateExpression& invokin
|
|||
}
|
||||
|
||||
auto value_with_number = [&](auto number) -> NonnullRefPtr<AST::Node> {
|
||||
return AST::create<AST::BarewordLiteral>(invoking_node.position(), String::number(number));
|
||||
return AST::make_ref_counted<AST::BarewordLiteral>(invoking_node.position(), String::number(number));
|
||||
};
|
||||
|
||||
auto do_across = [&](StringView mode_name, auto& values) {
|
||||
|
@ -78,17 +78,17 @@ RefPtr<AST::Node> Shell::immediate_length_impl(AST::ImmediateExpression& invokin
|
|||
resulting_nodes.ensure_capacity(values.size());
|
||||
for (auto& entry : values) {
|
||||
// ImmediateExpression(length <mode_name> <entry>)
|
||||
resulting_nodes.unchecked_append(AST::create<AST::ImmediateExpression>(
|
||||
resulting_nodes.unchecked_append(AST::make_ref_counted<AST::ImmediateExpression>(
|
||||
expr_node->position(),
|
||||
AST::NameWithPosition { "length", invoking_node.function_position() },
|
||||
NonnullRefPtrVector<AST::Node> { Vector<NonnullRefPtr<AST::Node>> {
|
||||
static_cast<NonnullRefPtr<AST::Node>>(AST::create<AST::BarewordLiteral>(expr_node->position(), mode_name)),
|
||||
AST::create<AST::SyntheticNode>(expr_node->position(), NonnullRefPtr<AST::Value>(entry)),
|
||||
static_cast<NonnullRefPtr<AST::Node>>(AST::make_ref_counted<AST::BarewordLiteral>(expr_node->position(), mode_name)),
|
||||
AST::make_ref_counted<AST::SyntheticNode>(expr_node->position(), NonnullRefPtr<AST::Value>(entry)),
|
||||
} },
|
||||
expr_node->position()));
|
||||
}
|
||||
|
||||
return AST::create<AST::ListConcatenate>(invoking_node.position(), move(resulting_nodes));
|
||||
return AST::make_ref_counted<AST::ListConcatenate>(invoking_node.position(), move(resulting_nodes));
|
||||
};
|
||||
|
||||
switch (mode) {
|
||||
|
@ -114,7 +114,7 @@ RefPtr<AST::Node> Shell::immediate_length_impl(AST::ImmediateExpression& invokin
|
|||
return value_with_number(list.size());
|
||||
|
||||
dbgln("List has {} entries", list.size());
|
||||
auto values = AST::create<AST::ListValue>(move(list));
|
||||
auto values = AST::make_ref_counted<AST::ListValue>(move(list));
|
||||
return do_across("list", values->values());
|
||||
}
|
||||
case String: {
|
||||
|
@ -183,7 +183,7 @@ RefPtr<AST::Node> Shell::immediate_length_impl(AST::ImmediateExpression& invokin
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
auto values = AST::create<AST::ListValue>(move(list));
|
||||
auto values = AST::make_ref_counted<AST::ListValue>(move(list));
|
||||
return do_across("string", values->values());
|
||||
}
|
||||
}
|
||||
|
@ -228,7 +228,7 @@ RefPtr<AST::Node> Shell::immediate_regex_replace(AST::ImmediateExpression& invok
|
|||
Regex<PosixExtendedParser> 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<AST::StringLiteral>(invoking_node.position(), move(result));
|
||||
return AST::make_ref_counted<AST::StringLiteral>(invoking_node.position(), move(result));
|
||||
}
|
||||
|
||||
RefPtr<AST::Node> Shell::immediate_remove_suffix(AST::ImmediateExpression& invoking_node, const NonnullRefPtrVector<AST::Node>& arguments)
|
||||
|
@ -256,10 +256,10 @@ RefPtr<AST::Node> 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<AST::StringLiteral>(invoking_node.position(), removed));
|
||||
nodes.append(AST::make_ref_counted<AST::StringLiteral>(invoking_node.position(), removed));
|
||||
}
|
||||
|
||||
return AST::create<AST::ListConcatenate>(invoking_node.position(), move(nodes));
|
||||
return AST::make_ref_counted<AST::ListConcatenate>(invoking_node.position(), move(nodes));
|
||||
}
|
||||
|
||||
RefPtr<AST::Node> Shell::immediate_remove_prefix(AST::ImmediateExpression& invoking_node, const NonnullRefPtrVector<AST::Node>& arguments)
|
||||
|
@ -287,10 +287,10 @@ RefPtr<AST::Node> 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<AST::StringLiteral>(invoking_node.position(), removed));
|
||||
nodes.append(AST::make_ref_counted<AST::StringLiteral>(invoking_node.position(), removed));
|
||||
}
|
||||
|
||||
return AST::create<AST::ListConcatenate>(invoking_node.position(), move(nodes));
|
||||
return AST::make_ref_counted<AST::ListConcatenate>(invoking_node.position(), move(nodes));
|
||||
}
|
||||
|
||||
RefPtr<AST::Node> Shell::immediate_split(AST::ImmediateExpression& invoking_node, const NonnullRefPtrVector<AST::Node>& arguments)
|
||||
|
@ -316,17 +316,17 @@ RefPtr<AST::Node> Shell::immediate_split(AST::ImmediateExpression& invoking_node
|
|||
resulting_nodes.ensure_capacity(values.size());
|
||||
for (auto& entry : values) {
|
||||
// ImmediateExpression(split <delimiter> <entry>)
|
||||
resulting_nodes.unchecked_append(AST::create<AST::ImmediateExpression>(
|
||||
resulting_nodes.unchecked_append(AST::make_ref_counted<AST::ImmediateExpression>(
|
||||
arguments[1].position(),
|
||||
invoking_node.function(),
|
||||
NonnullRefPtrVector<AST::Node> { Vector<NonnullRefPtr<AST::Node>> {
|
||||
arguments[0],
|
||||
AST::create<AST::SyntheticNode>(arguments[1].position(), NonnullRefPtr<AST::Value>(entry)),
|
||||
AST::make_ref_counted<AST::SyntheticNode>(arguments[1].position(), NonnullRefPtr<AST::Value>(entry)),
|
||||
} },
|
||||
arguments[1].position()));
|
||||
}
|
||||
|
||||
return AST::create<AST::ListConcatenate>(invoking_node.position(), move(resulting_nodes));
|
||||
return AST::make_ref_counted<AST::ListConcatenate>(invoking_node.position(), move(resulting_nodes));
|
||||
};
|
||||
|
||||
if (auto list = dynamic_cast<AST::ListValue*>(value.ptr())) {
|
||||
|
@ -337,7 +337,7 @@ RefPtr<AST::Node> 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<AST::ListConcatenate>(invoking_node.position(), NonnullRefPtrVector<AST::Node> {});
|
||||
return AST::make_ref_counted<AST::ListConcatenate>(invoking_node.position(), NonnullRefPtrVector<AST::Node> {});
|
||||
|
||||
auto& value = list.first();
|
||||
Vector<String> split_strings;
|
||||
|
@ -354,10 +354,10 @@ RefPtr<AST::Node> Shell::immediate_split(AST::ImmediateExpression& invoking_node
|
|||
for (auto& entry : split)
|
||||
split_strings.append(entry);
|
||||
}
|
||||
return AST::create<AST::SyntheticNode>(invoking_node.position(), AST::create<AST::ListValue>(move(split_strings)));
|
||||
return AST::make_ref_counted<AST::SyntheticNode>(invoking_node.position(), AST::make_ref_counted<AST::ListValue>(move(split_strings)));
|
||||
}
|
||||
|
||||
return transform(AST::create<AST::ListValue>(list)->values());
|
||||
return transform(AST::make_ref_counted<AST::ListValue>(list)->values());
|
||||
}
|
||||
|
||||
RefPtr<AST::Node> Shell::immediate_concat_lists(AST::ImmediateExpression& invoking_node, const NonnullRefPtrVector<AST::Node>& arguments)
|
||||
|
@ -371,16 +371,16 @@ RefPtr<AST::Node> Shell::immediate_concat_lists(AST::ImmediateExpression& invoki
|
|||
auto list_of_values = const_cast<AST::Node&>(argument).run(this)->resolve_without_cast(this);
|
||||
if (auto* list = dynamic_cast<AST::ListValue*>(list_of_values.ptr())) {
|
||||
for (auto& entry : static_cast<Vector<NonnullRefPtr<AST::Value>>&>(list->values()))
|
||||
result.append(AST::create<AST::SyntheticNode>(argument.position(), entry));
|
||||
result.append(AST::make_ref_counted<AST::SyntheticNode>(argument.position(), entry));
|
||||
} else {
|
||||
auto values = list_of_values->resolve_as_list(this);
|
||||
for (auto& entry : values)
|
||||
result.append(AST::create<AST::StringLiteral>(argument.position(), entry));
|
||||
result.append(AST::make_ref_counted<AST::StringLiteral>(argument.position(), entry));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return AST::create<AST::ListConcatenate>(invoking_node.position(), move(result));
|
||||
return AST::make_ref_counted<AST::ListConcatenate>(invoking_node.position(), move(result));
|
||||
}
|
||||
|
||||
RefPtr<AST::Node> Shell::run_immediate_function(StringView str, AST::ImmediateExpression& invoking_node, const NonnullRefPtrVector<AST::Node>& arguments)
|
||||
|
|
Loading…
Reference in a new issue