/src/serenity/Userland/Libraries/LibShell/NodeVisitor.cpp
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2020, the SerenityOS developers. |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #include "NodeVisitor.h" |
8 | | #include "AST.h" |
9 | | |
10 | | namespace Shell::AST { |
11 | | |
12 | | void NodeVisitor::visit(const AST::PathRedirectionNode* node) |
13 | 0 | { |
14 | 0 | node->path()->visit(*this); |
15 | 0 | } |
16 | | |
17 | | void NodeVisitor::visit(const AST::And* node) |
18 | 0 | { |
19 | 0 | node->left()->visit(*this); |
20 | 0 | node->right()->visit(*this); |
21 | 0 | } |
22 | | |
23 | | void NodeVisitor::visit(const AST::ListConcatenate* node) |
24 | 0 | { |
25 | 0 | for (auto& subnode : node->list()) |
26 | 0 | subnode->visit(*this); |
27 | 0 | } |
28 | | |
29 | | void NodeVisitor::visit(const AST::Background* node) |
30 | 0 | { |
31 | 0 | node->command()->visit(*this); |
32 | 0 | } |
33 | | |
34 | | void NodeVisitor::visit(const AST::BarewordLiteral*) |
35 | 0 | { |
36 | 0 | } |
37 | | |
38 | | void NodeVisitor::visit(const AST::BraceExpansion* node) |
39 | 0 | { |
40 | 0 | for (auto& entry : node->entries()) |
41 | 0 | entry->visit(*this); |
42 | 0 | } |
43 | | |
44 | | void NodeVisitor::visit(const AST::CastToCommand* node) |
45 | 0 | { |
46 | 0 | node->inner()->visit(*this); |
47 | 0 | } |
48 | | |
49 | | void NodeVisitor::visit(const AST::CastToList* node) |
50 | 0 | { |
51 | 0 | if (node->inner()) |
52 | 0 | node->inner()->visit(*this); |
53 | 0 | } |
54 | | |
55 | | void NodeVisitor::visit(const AST::CloseFdRedirection*) |
56 | 0 | { |
57 | 0 | } |
58 | | |
59 | | void NodeVisitor::visit(const AST::CommandLiteral*) |
60 | 0 | { |
61 | 0 | } |
62 | | |
63 | | void NodeVisitor::visit(const AST::Comment*) |
64 | 0 | { |
65 | 0 | } |
66 | | |
67 | | void NodeVisitor::visit(const AST::ContinuationControl*) |
68 | 0 | { |
69 | 0 | } |
70 | | |
71 | | void NodeVisitor::visit(const AST::DynamicEvaluate* node) |
72 | 0 | { |
73 | 0 | node->inner()->visit(*this); |
74 | 0 | } |
75 | | |
76 | | void NodeVisitor::visit(const AST::DoubleQuotedString* node) |
77 | 0 | { |
78 | 0 | if (node->inner()) |
79 | 0 | node->inner()->visit(*this); |
80 | 0 | } |
81 | | |
82 | | void NodeVisitor::visit(const AST::Fd2FdRedirection*) |
83 | 0 | { |
84 | 0 | } |
85 | | |
86 | | void NodeVisitor::visit(const AST::FunctionDeclaration* node) |
87 | 0 | { |
88 | 0 | if (node->block()) |
89 | 0 | node->block()->visit(*this); |
90 | 0 | } |
91 | | |
92 | | void NodeVisitor::visit(const AST::ForLoop* node) |
93 | 0 | { |
94 | 0 | if (node->iterated_expression()) |
95 | 0 | node->iterated_expression()->visit(*this); |
96 | 0 | if (node->block()) |
97 | 0 | node->block()->visit(*this); |
98 | 0 | } |
99 | | |
100 | | void NodeVisitor::visit(const AST::Glob*) |
101 | 0 | { |
102 | 0 | } |
103 | | |
104 | | void NodeVisitor::visit(const AST::Heredoc* node) |
105 | 0 | { |
106 | 0 | if (node->contents()) |
107 | 0 | node->contents()->visit(*this); |
108 | 0 | } |
109 | | |
110 | | void NodeVisitor::visit(const AST::HistoryEvent*) |
111 | 0 | { |
112 | 0 | } |
113 | | |
114 | | void NodeVisitor::visit(const AST::Execute* node) |
115 | 0 | { |
116 | 0 | node->command()->visit(*this); |
117 | 0 | } |
118 | | |
119 | | void NodeVisitor::visit(const AST::IfCond* node) |
120 | 0 | { |
121 | 0 | node->condition()->visit(*this); |
122 | 0 | if (node->true_branch()) |
123 | 0 | node->true_branch()->visit(*this); |
124 | 0 | if (node->false_branch()) |
125 | 0 | node->false_branch()->visit(*this); |
126 | 0 | } |
127 | | |
128 | | void NodeVisitor::visit(const AST::ImmediateExpression* node) |
129 | 0 | { |
130 | 0 | for (auto& node : node->arguments()) |
131 | 0 | node->visit(*this); |
132 | 0 | } |
133 | | |
134 | | void NodeVisitor::visit(const AST::Join* node) |
135 | 0 | { |
136 | 0 | node->left()->visit(*this); |
137 | 0 | node->right()->visit(*this); |
138 | 0 | } |
139 | | |
140 | | void NodeVisitor::visit(const AST::MatchExpr* node) |
141 | 0 | { |
142 | 0 | node->matched_expr()->visit(*this); |
143 | 0 | for (auto& entry : node->entries()) { |
144 | 0 | if (auto* ptr = entry.options.get_pointer<Vector<NonnullRefPtr<Node>>>()) { |
145 | 0 | for (auto& option : *ptr) |
146 | 0 | option->visit(*this); |
147 | 0 | } |
148 | 0 | if (entry.body) |
149 | 0 | entry.body->visit(*this); |
150 | 0 | } |
151 | 0 | } |
152 | | |
153 | | void NodeVisitor::visit(const AST::Or* node) |
154 | 0 | { |
155 | 0 | node->left()->visit(*this); |
156 | 0 | node->right()->visit(*this); |
157 | 0 | } |
158 | | |
159 | | void NodeVisitor::visit(const AST::Pipe* node) |
160 | 0 | { |
161 | 0 | node->left()->visit(*this); |
162 | 0 | node->right()->visit(*this); |
163 | 0 | } |
164 | | |
165 | | void NodeVisitor::visit(const AST::Range* node) |
166 | 0 | { |
167 | 0 | node->start()->visit(*this); |
168 | 0 | node->end()->visit(*this); |
169 | 0 | } |
170 | | |
171 | | void NodeVisitor::visit(const AST::ReadRedirection* node) |
172 | 0 | { |
173 | 0 | visit(static_cast<const AST::PathRedirectionNode*>(node)); |
174 | 0 | } |
175 | | |
176 | | void NodeVisitor::visit(const AST::ReadWriteRedirection* node) |
177 | 0 | { |
178 | 0 | visit(static_cast<const AST::PathRedirectionNode*>(node)); |
179 | 0 | } |
180 | | |
181 | | void NodeVisitor::visit(const AST::Sequence* node) |
182 | 0 | { |
183 | 0 | for (auto& entry : node->entries()) |
184 | 0 | entry->visit(*this); |
185 | 0 | } |
186 | | |
187 | | void NodeVisitor::visit(const AST::Subshell* node) |
188 | 0 | { |
189 | 0 | if (node->block()) |
190 | 0 | node->block()->visit(*this); |
191 | 0 | } |
192 | | |
193 | | void NodeVisitor::visit(const AST::Slice* node) |
194 | 0 | { |
195 | 0 | node->selector()->visit(*this); |
196 | 0 | } |
197 | | |
198 | | void NodeVisitor::visit(const AST::SimpleVariable* node) |
199 | 0 | { |
200 | 0 | if (const AST::Node* slice = node->slice()) |
201 | 0 | slice->visit(*this); |
202 | 0 | } |
203 | | |
204 | | void NodeVisitor::visit(const AST::SpecialVariable* node) |
205 | 0 | { |
206 | 0 | if (const AST::Node* slice = node->slice()) |
207 | 0 | slice->visit(*this); |
208 | 0 | } |
209 | | |
210 | | void NodeVisitor::visit(const AST::Juxtaposition* node) |
211 | 0 | { |
212 | 0 | node->left()->visit(*this); |
213 | 0 | node->right()->visit(*this); |
214 | 0 | } |
215 | | |
216 | | void NodeVisitor::visit(const AST::StringLiteral*) |
217 | 0 | { |
218 | 0 | } |
219 | | |
220 | | void NodeVisitor::visit(const AST::StringPartCompose* node) |
221 | 0 | { |
222 | 0 | node->left()->visit(*this); |
223 | 0 | node->right()->visit(*this); |
224 | 0 | } |
225 | | |
226 | | void NodeVisitor::visit(const AST::SyntaxError*) |
227 | 0 | { |
228 | 0 | } |
229 | | |
230 | | void NodeVisitor::visit(const AST::SyntheticNode*) |
231 | 0 | { |
232 | 0 | } |
233 | | |
234 | | void NodeVisitor::visit(const AST::Tilde*) |
235 | 0 | { |
236 | 0 | } |
237 | | |
238 | | void NodeVisitor::visit(const AST::VariableDeclarations* node) |
239 | 0 | { |
240 | 0 | for (auto& entry : node->variables()) { |
241 | 0 | entry.name->visit(*this); |
242 | 0 | entry.value->visit(*this); |
243 | 0 | } |
244 | 0 | } |
245 | | |
246 | | void NodeVisitor::visit(const AST::WriteAppendRedirection* node) |
247 | 0 | { |
248 | 0 | visit(static_cast<const AST::PathRedirectionNode*>(node)); |
249 | 0 | } |
250 | | |
251 | | void NodeVisitor::visit(const AST::WriteRedirection* node) |
252 | 0 | { |
253 | 0 | visit(static_cast<const AST::PathRedirectionNode*>(node)); |
254 | 0 | } |
255 | | |
256 | | } |