2020-09-15 20:43:04 -04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
|
|
|
*
|
2021-04-22 04:24:48 -04:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-09-15 20:43:04 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "NodeVisitor.h"
|
|
|
|
#include "AST.h"
|
|
|
|
|
2020-10-01 10:43:01 -04:00
|
|
|
namespace Shell::AST {
|
2020-09-15 20:43:04 -04:00
|
|
|
|
|
|
|
void NodeVisitor::visit(const AST::PathRedirectionNode* node)
|
|
|
|
{
|
|
|
|
node->path()->visit(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeVisitor::visit(const AST::And* node)
|
|
|
|
{
|
|
|
|
node->left()->visit(*this);
|
|
|
|
node->right()->visit(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeVisitor::visit(const AST::ListConcatenate* node)
|
|
|
|
{
|
|
|
|
for (auto& subnode : node->list())
|
|
|
|
subnode->visit(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeVisitor::visit(const AST::Background* node)
|
|
|
|
{
|
|
|
|
node->command()->visit(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeVisitor::visit(const AST::BarewordLiteral*)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-10-24 10:43:02 -04:00
|
|
|
void NodeVisitor::visit(const AST::BraceExpansion* node)
|
|
|
|
{
|
|
|
|
for (auto& entry : node->entries())
|
2023-03-06 08:17:01 -05:00
|
|
|
entry->visit(*this);
|
2020-10-24 10:43:02 -04:00
|
|
|
}
|
|
|
|
|
2020-09-15 20:43:04 -04:00
|
|
|
void NodeVisitor::visit(const AST::CastToCommand* node)
|
|
|
|
{
|
|
|
|
node->inner()->visit(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeVisitor::visit(const AST::CastToList* node)
|
|
|
|
{
|
|
|
|
if (node->inner())
|
|
|
|
node->inner()->visit(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeVisitor::visit(const AST::CloseFdRedirection*)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeVisitor::visit(const AST::CommandLiteral*)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeVisitor::visit(const AST::Comment*)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-12-10 09:55:13 -05:00
|
|
|
void NodeVisitor::visit(const AST::ContinuationControl*)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-09-15 20:43:04 -04:00
|
|
|
void NodeVisitor::visit(const AST::DynamicEvaluate* node)
|
|
|
|
{
|
|
|
|
node->inner()->visit(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeVisitor::visit(const AST::DoubleQuotedString* node)
|
|
|
|
{
|
|
|
|
if (node->inner())
|
|
|
|
node->inner()->visit(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeVisitor::visit(const AST::Fd2FdRedirection*)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeVisitor::visit(const AST::FunctionDeclaration* node)
|
|
|
|
{
|
|
|
|
if (node->block())
|
|
|
|
node->block()->visit(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeVisitor::visit(const AST::ForLoop* node)
|
|
|
|
{
|
2020-12-10 09:55:13 -05:00
|
|
|
if (node->iterated_expression())
|
|
|
|
node->iterated_expression()->visit(*this);
|
2020-09-15 20:43:04 -04:00
|
|
|
if (node->block())
|
|
|
|
node->block()->visit(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeVisitor::visit(const AST::Glob*)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-04-28 22:34:00 -04:00
|
|
|
void NodeVisitor::visit(const AST::Heredoc* node)
|
|
|
|
{
|
|
|
|
if (node->contents())
|
|
|
|
node->contents()->visit(*this);
|
|
|
|
}
|
|
|
|
|
2021-01-11 04:34:59 -05:00
|
|
|
void NodeVisitor::visit(const AST::HistoryEvent*)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-09-15 20:43:04 -04:00
|
|
|
void NodeVisitor::visit(const AST::Execute* node)
|
|
|
|
{
|
|
|
|
node->command()->visit(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeVisitor::visit(const AST::IfCond* node)
|
|
|
|
{
|
|
|
|
node->condition()->visit(*this);
|
|
|
|
if (node->true_branch())
|
|
|
|
node->true_branch()->visit(*this);
|
|
|
|
if (node->false_branch())
|
|
|
|
node->false_branch()->visit(*this);
|
|
|
|
}
|
|
|
|
|
2021-03-05 08:03:23 -05:00
|
|
|
void NodeVisitor::visit(const AST::ImmediateExpression* node)
|
|
|
|
{
|
|
|
|
for (auto& node : node->arguments())
|
2023-03-06 08:17:01 -05:00
|
|
|
node->visit(*this);
|
2021-03-05 08:03:23 -05:00
|
|
|
}
|
|
|
|
|
2020-09-15 20:43:04 -04:00
|
|
|
void NodeVisitor::visit(const AST::Join* node)
|
|
|
|
{
|
|
|
|
node->left()->visit(*this);
|
|
|
|
node->right()->visit(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeVisitor::visit(const AST::MatchExpr* node)
|
|
|
|
{
|
|
|
|
node->matched_expr()->visit(*this);
|
|
|
|
for (auto& entry : node->entries()) {
|
2023-03-06 08:17:01 -05:00
|
|
|
if (auto* ptr = entry.options.get_pointer<Vector<NonnullRefPtr<Node>>>()) {
|
2022-04-14 17:20:36 -04:00
|
|
|
for (auto& option : *ptr)
|
2023-03-06 08:17:01 -05:00
|
|
|
option->visit(*this);
|
2022-04-14 17:20:36 -04:00
|
|
|
}
|
2020-09-15 20:43:04 -04:00
|
|
|
if (entry.body)
|
|
|
|
entry.body->visit(*this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeVisitor::visit(const AST::Or* node)
|
|
|
|
{
|
|
|
|
node->left()->visit(*this);
|
|
|
|
node->right()->visit(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeVisitor::visit(const AST::Pipe* node)
|
|
|
|
{
|
|
|
|
node->left()->visit(*this);
|
|
|
|
node->right()->visit(*this);
|
|
|
|
}
|
|
|
|
|
2020-10-24 10:43:02 -04:00
|
|
|
void NodeVisitor::visit(const AST::Range* node)
|
|
|
|
{
|
|
|
|
node->start()->visit(*this);
|
|
|
|
node->end()->visit(*this);
|
|
|
|
}
|
|
|
|
|
2020-09-15 20:43:04 -04:00
|
|
|
void NodeVisitor::visit(const AST::ReadRedirection* node)
|
|
|
|
{
|
|
|
|
visit(static_cast<const AST::PathRedirectionNode*>(node));
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeVisitor::visit(const AST::ReadWriteRedirection* node)
|
|
|
|
{
|
|
|
|
visit(static_cast<const AST::PathRedirectionNode*>(node));
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeVisitor::visit(const AST::Sequence* node)
|
|
|
|
{
|
2021-01-16 14:50:52 -05:00
|
|
|
for (auto& entry : node->entries())
|
2023-03-06 08:17:01 -05:00
|
|
|
entry->visit(*this);
|
2020-09-15 20:43:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void NodeVisitor::visit(const AST::Subshell* node)
|
|
|
|
{
|
|
|
|
if (node->block())
|
|
|
|
node->block()->visit(*this);
|
|
|
|
}
|
|
|
|
|
2021-03-12 18:40:18 -05:00
|
|
|
void NodeVisitor::visit(const AST::Slice* node)
|
2020-09-15 20:43:04 -04:00
|
|
|
{
|
2021-03-12 18:40:18 -05:00
|
|
|
node->selector()->visit(*this);
|
2020-09-15 20:43:04 -04:00
|
|
|
}
|
|
|
|
|
2021-03-12 18:40:18 -05:00
|
|
|
void NodeVisitor::visit(const AST::SimpleVariable* node)
|
2020-09-15 20:43:04 -04:00
|
|
|
{
|
2021-03-12 18:40:18 -05:00
|
|
|
if (const AST::Node* slice = node->slice())
|
|
|
|
slice->visit(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeVisitor::visit(const AST::SpecialVariable* node)
|
|
|
|
{
|
|
|
|
if (const AST::Node* slice = node->slice())
|
|
|
|
slice->visit(*this);
|
2020-09-15 20:43:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void NodeVisitor::visit(const AST::Juxtaposition* node)
|
|
|
|
{
|
|
|
|
node->left()->visit(*this);
|
|
|
|
node->right()->visit(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeVisitor::visit(const AST::StringLiteral*)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeVisitor::visit(const AST::StringPartCompose* node)
|
|
|
|
{
|
|
|
|
node->left()->visit(*this);
|
|
|
|
node->right()->visit(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeVisitor::visit(const AST::SyntaxError*)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-03-05 08:03:23 -05:00
|
|
|
void NodeVisitor::visit(const AST::SyntheticNode*)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-09-15 20:43:04 -04:00
|
|
|
void NodeVisitor::visit(const AST::Tilde*)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeVisitor::visit(const AST::VariableDeclarations* node)
|
|
|
|
{
|
|
|
|
for (auto& entry : node->variables()) {
|
|
|
|
entry.name->visit(*this);
|
|
|
|
entry.value->visit(*this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeVisitor::visit(const AST::WriteAppendRedirection* node)
|
|
|
|
{
|
|
|
|
visit(static_cast<const AST::PathRedirectionNode*>(node));
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeVisitor::visit(const AST::WriteRedirection* node)
|
|
|
|
{
|
|
|
|
visit(static_cast<const AST::PathRedirectionNode*>(node));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|