mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-10 13:00:29 +03:00
Shell: Use NonnullRefPtr to simplify some things in the parser/AST
This commit is contained in:
parent
7a3ab6c517
commit
3cb8ae873c
Notes:
sideshowbarker
2024-07-19 04:18:52 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/3cb8ae873c3
@ -2041,24 +2041,24 @@ Vector<String> TildeValue::resolve_as_list(RefPtr<Shell> shell)
|
||||
return { shell->expand_tilde(builder.to_string()) };
|
||||
}
|
||||
|
||||
Result<RefPtr<Rewiring>, String> CloseRedirection::apply() const
|
||||
Result<NonnullRefPtr<Rewiring>, String> CloseRedirection::apply() const
|
||||
{
|
||||
return static_cast<RefPtr<Rewiring>>((adopt(*new Rewiring(fd, fd, Rewiring::Close::ImmediatelyCloseDestination))));
|
||||
return adopt(*new Rewiring(fd, fd, Rewiring::Close::ImmediatelyCloseDestination));
|
||||
}
|
||||
|
||||
CloseRedirection::~CloseRedirection()
|
||||
{
|
||||
}
|
||||
|
||||
Result<RefPtr<Rewiring>, String> PathRedirection::apply() const
|
||||
Result<NonnullRefPtr<Rewiring>, String> PathRedirection::apply() const
|
||||
{
|
||||
auto check_fd_and_return = [my_fd = this->fd](int fd, const String& path) -> Result<RefPtr<Rewiring>, String> {
|
||||
auto check_fd_and_return = [my_fd = this->fd](int fd, const String& path) -> Result<NonnullRefPtr<Rewiring>, String> {
|
||||
if (fd < 0) {
|
||||
String error = strerror(errno);
|
||||
dbg() << "open() failed for '" << path << "' with " << error;
|
||||
return error;
|
||||
}
|
||||
return static_cast<RefPtr<Rewiring>>((adopt(*new Rewiring(my_fd, fd, Rewiring::Close::Destination))));
|
||||
return adopt(*new Rewiring(my_fd, fd, Rewiring::Close::Destination));
|
||||
};
|
||||
switch (direction) {
|
||||
case AST::PathRedirection::WriteAppend:
|
||||
|
10
Shell/AST.h
10
Shell/AST.h
@ -78,7 +78,7 @@ struct Rewiring : public RefCounted<Rewiring> {
|
||||
};
|
||||
|
||||
struct Redirection : public RefCounted<Redirection> {
|
||||
virtual Result<RefPtr<Rewiring>, String> apply() const = 0;
|
||||
virtual Result<NonnullRefPtr<Rewiring>, String> apply() const = 0;
|
||||
virtual ~Redirection();
|
||||
virtual bool is_path_redirection() const { return false; }
|
||||
virtual bool is_fd_redirection() const { return false; }
|
||||
@ -88,7 +88,7 @@ struct Redirection : public RefCounted<Redirection> {
|
||||
struct CloseRedirection : public Redirection {
|
||||
int fd { -1 };
|
||||
|
||||
virtual Result<RefPtr<Rewiring>, String> apply() const override;
|
||||
virtual Result<NonnullRefPtr<Rewiring>, String> apply() const override;
|
||||
virtual ~CloseRedirection();
|
||||
CloseRedirection(int fd)
|
||||
: fd(fd)
|
||||
@ -109,7 +109,7 @@ struct PathRedirection : public Redirection {
|
||||
ReadWrite,
|
||||
} direction { Read };
|
||||
|
||||
virtual Result<RefPtr<Rewiring>, String> apply() const override;
|
||||
virtual Result<NonnullRefPtr<Rewiring>, String> apply() const override;
|
||||
virtual ~PathRedirection();
|
||||
PathRedirection(String path, int fd, decltype(direction) direction)
|
||||
: path(move(path))
|
||||
@ -123,9 +123,9 @@ private:
|
||||
};
|
||||
|
||||
struct FdRedirection : public Redirection {
|
||||
virtual Result<RefPtr<Rewiring>, String> apply() const override
|
||||
virtual Result<NonnullRefPtr<Rewiring>, String> apply() const override
|
||||
{
|
||||
return RefPtr<Rewiring>(adopt(*new Rewiring(source_fd, dest_fd, other_pipe_end, action)));
|
||||
return adopt(*new Rewiring(source_fd, dest_fd, other_pipe_end, action));
|
||||
}
|
||||
virtual ~FdRedirection();
|
||||
FdRedirection(int source, int dest, Rewiring::Close close)
|
||||
|
@ -72,7 +72,7 @@ bool Parser::expect(const StringView& expected)
|
||||
}
|
||||
|
||||
template<typename A, typename... Args>
|
||||
RefPtr<A> Parser::create(Args... args)
|
||||
NonnullRefPtr<A> Parser::create(Args... args)
|
||||
{
|
||||
return adopt(*new A(AST::Position { m_rule_start_offsets.last(), m_offset }, args...));
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ private:
|
||||
RefPtr<AST::Node> parse_glob();
|
||||
|
||||
template<typename A, typename... Args>
|
||||
RefPtr<A> create(Args... args);
|
||||
NonnullRefPtr<A> create(Args... args);
|
||||
|
||||
bool at_end() const { return m_input.length() <= m_offset; }
|
||||
char peek();
|
||||
|
Loading…
Reference in New Issue
Block a user