NodeVisitor.cpp 5.0 KB

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