123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- /*
- * Copyright (c) 2020, the SerenityOS developers.
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
- #include "NodeVisitor.h"
- #include "AST.h"
- namespace Shell::AST {
- 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*)
- {
- }
- void NodeVisitor::visit(const AST::BraceExpansion* node)
- {
- for (auto& entry : node->entries())
- entry.visit(*this);
- }
- 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*)
- {
- }
- void NodeVisitor::visit(const AST::ContinuationControl*)
- {
- }
- 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)
- {
- if (node->iterated_expression())
- node->iterated_expression()->visit(*this);
- if (node->block())
- node->block()->visit(*this);
- }
- void NodeVisitor::visit(const AST::Glob*)
- {
- }
- void NodeVisitor::visit(const AST::Heredoc* node)
- {
- if (node->contents())
- node->contents()->visit(*this);
- }
- void NodeVisitor::visit(const AST::HistoryEvent*)
- {
- }
- 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);
- }
- void NodeVisitor::visit(const AST::ImmediateExpression* node)
- {
- for (auto& node : node->arguments())
- node.visit(*this);
- }
- 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);
- }
- void NodeVisitor::visit(const AST::Range* node)
- {
- node->start()->visit(*this);
- node->end()->visit(*this);
- }
- 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)
- {
- for (auto& entry : node->entries())
- entry.visit(*this);
- }
- void NodeVisitor::visit(const AST::Subshell* node)
- {
- if (node->block())
- node->block()->visit(*this);
- }
- void NodeVisitor::visit(const AST::Slice* node)
- {
- node->selector()->visit(*this);
- }
- void NodeVisitor::visit(const AST::SimpleVariable* node)
- {
- 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);
- }
- 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*)
- {
- }
- void NodeVisitor::visit(const AST::SyntheticNode*)
- {
- }
- 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));
- }
- }
|