2020-09-16 05:13:04 +04:30
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-09-16 05:13:04 +04:30
|
|
|
*/
|
|
|
|
|
|
|
|
#include "NodeVisitor.h"
|
|
|
|
#include "AST.h"
|
|
|
|
|
2020-10-01 18:13:01 +03:30
|
|
|
namespace Shell::AST {
|
2020-09-16 05:13:04 +04:30
|
|
|
|
|
|
|
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 18:13:02 +03:30
|
|
|
void NodeVisitor::visit(const AST::BraceExpansion* node)
|
|
|
|
{
|
|
|
|
for (auto& entry : node->entries())
|
|
|
|
entry.visit(*this);
|
|
|
|
}
|
|
|
|
|
2020-09-16 05:13:04 +04:30
|
|
|
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 18:25:13 +03:30
|
|
|
void NodeVisitor::visit(const AST::ContinuationControl*)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-09-16 05:13:04 +04:30
|
|
|
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 18:25:13 +03:30
|
|
|
if (node->iterated_expression())
|
|
|
|
node->iterated_expression()->visit(*this);
|
2020-09-16 05:13:04 +04:30
|
|
|
if (node->block())
|
|
|
|
node->block()->visit(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NodeVisitor::visit(const AST::Glob*)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-04-29 07:04:00 +04:30
|
|
|
void NodeVisitor::visit(const AST::Heredoc* node)
|
|
|
|
{
|
|
|
|
if (node->contents())
|
|
|
|
node->contents()->visit(*this);
|
|
|
|
}
|
|
|
|
|
2021-01-11 13:04:59 +03:30
|
|
|
void NodeVisitor::visit(const AST::HistoryEvent*)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-09-16 05:13:04 +04:30
|
|
|
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 16:33:23 +03:30
|
|
|
void NodeVisitor::visit(const AST::ImmediateExpression* node)
|
|
|
|
{
|
|
|
|
for (auto& node : node->arguments())
|
|
|
|
node.visit(*this);
|
|
|
|
}
|
|
|
|
|
2020-09-16 05:13:04 +04:30
|
|
|
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()) {
|
|
|
|
for (auto& option : entry.options)
|
|
|
|
option.visit(*this);
|
|
|
|
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 18:13:02 +03:30
|
|
|
void NodeVisitor::visit(const AST::Range* node)
|
|
|
|
{
|
|
|
|
node->start()->visit(*this);
|
|
|
|
node->end()->visit(*this);
|
|
|
|
}
|
|
|
|
|
2020-09-16 05:13:04 +04:30
|
|
|
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 23:20:52 +03:30
|
|
|
for (auto& entry : node->entries())
|
|
|
|
entry.visit(*this);
|
2020-09-16 05:13:04 +04:30
|
|
|
}
|
|
|
|
|
|
|
|
void NodeVisitor::visit(const AST::Subshell* node)
|
|
|
|
{
|
|
|
|
if (node->block())
|
|
|
|
node->block()->visit(*this);
|
|
|
|
}
|
|
|
|
|
2021-03-13 03:10:18 +03:30
|
|
|
void NodeVisitor::visit(const AST::Slice* node)
|
2020-09-16 05:13:04 +04:30
|
|
|
{
|
2021-03-13 03:10:18 +03:30
|
|
|
node->selector()->visit(*this);
|
2020-09-16 05:13:04 +04:30
|
|
|
}
|
|
|
|
|
2021-03-13 03:10:18 +03:30
|
|
|
void NodeVisitor::visit(const AST::SimpleVariable* node)
|
2020-09-16 05:13:04 +04:30
|
|
|
{
|
2021-03-13 03:10:18 +03:30
|
|
|
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-16 05:13:04 +04:30
|
|
|
}
|
|
|
|
|
|
|
|
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 16:33:23 +03:30
|
|
|
void NodeVisitor::visit(const AST::SyntheticNode*)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-09-16 05:13:04 +04:30
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|