mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 19:57:41 +00:00
Shell: Use NonnullRefPtr to simplify some things in the parser/AST
This commit is contained in:
parent
7a3ab6c517
commit
3cb8ae873c
4 changed files with 12 additions and 12 deletions
|
@ -2041,24 +2041,24 @@ Vector<String> TildeValue::resolve_as_list(RefPtr<Shell> shell)
|
||||||
return { shell->expand_tilde(builder.to_string()) };
|
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()
|
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) {
|
if (fd < 0) {
|
||||||
String error = strerror(errno);
|
String error = strerror(errno);
|
||||||
dbg() << "open() failed for '" << path << "' with " << error;
|
dbg() << "open() failed for '" << path << "' with " << error;
|
||||||
return 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) {
|
switch (direction) {
|
||||||
case AST::PathRedirection::WriteAppend:
|
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> {
|
struct Redirection : public RefCounted<Redirection> {
|
||||||
virtual Result<RefPtr<Rewiring>, String> apply() const = 0;
|
virtual Result<NonnullRefPtr<Rewiring>, String> apply() const = 0;
|
||||||
virtual ~Redirection();
|
virtual ~Redirection();
|
||||||
virtual bool is_path_redirection() const { return false; }
|
virtual bool is_path_redirection() const { return false; }
|
||||||
virtual bool is_fd_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 {
|
struct CloseRedirection : public Redirection {
|
||||||
int fd { -1 };
|
int fd { -1 };
|
||||||
|
|
||||||
virtual Result<RefPtr<Rewiring>, String> apply() const override;
|
virtual Result<NonnullRefPtr<Rewiring>, String> apply() const override;
|
||||||
virtual ~CloseRedirection();
|
virtual ~CloseRedirection();
|
||||||
CloseRedirection(int fd)
|
CloseRedirection(int fd)
|
||||||
: fd(fd)
|
: fd(fd)
|
||||||
|
@ -109,7 +109,7 @@ struct PathRedirection : public Redirection {
|
||||||
ReadWrite,
|
ReadWrite,
|
||||||
} direction { Read };
|
} direction { Read };
|
||||||
|
|
||||||
virtual Result<RefPtr<Rewiring>, String> apply() const override;
|
virtual Result<NonnullRefPtr<Rewiring>, String> apply() const override;
|
||||||
virtual ~PathRedirection();
|
virtual ~PathRedirection();
|
||||||
PathRedirection(String path, int fd, decltype(direction) direction)
|
PathRedirection(String path, int fd, decltype(direction) direction)
|
||||||
: path(move(path))
|
: path(move(path))
|
||||||
|
@ -123,9 +123,9 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FdRedirection : public Redirection {
|
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();
|
virtual ~FdRedirection();
|
||||||
FdRedirection(int source, int dest, Rewiring::Close close)
|
FdRedirection(int source, int dest, Rewiring::Close close)
|
||||||
|
|
|
@ -72,7 +72,7 @@ bool Parser::expect(const StringView& expected)
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename A, typename... Args>
|
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...));
|
return adopt(*new A(AST::Position { m_rule_start_offsets.last(), m_offset }, args...));
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ private:
|
||||||
RefPtr<AST::Node> parse_glob();
|
RefPtr<AST::Node> parse_glob();
|
||||||
|
|
||||||
template<typename A, typename... Args>
|
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; }
|
bool at_end() const { return m_input.length() <= m_offset; }
|
||||||
char peek();
|
char peek();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue