NodeVisitor.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #include "NodeVisitor.h"
  27. #include "AST.h"
  28. namespace Shell::AST {
  29. void NodeVisitor::visit(const AST::PathRedirectionNode* node)
  30. {
  31. node->path()->visit(*this);
  32. }
  33. void NodeVisitor::visit(const AST::And* node)
  34. {
  35. node->left()->visit(*this);
  36. node->right()->visit(*this);
  37. }
  38. void NodeVisitor::visit(const AST::ListConcatenate* node)
  39. {
  40. for (auto& subnode : node->list())
  41. subnode->visit(*this);
  42. }
  43. void NodeVisitor::visit(const AST::Background* node)
  44. {
  45. node->command()->visit(*this);
  46. }
  47. void NodeVisitor::visit(const AST::BarewordLiteral*)
  48. {
  49. }
  50. void NodeVisitor::visit(const AST::BraceExpansion* node)
  51. {
  52. for (auto& entry : node->entries())
  53. entry.visit(*this);
  54. }
  55. void NodeVisitor::visit(const AST::CastToCommand* node)
  56. {
  57. node->inner()->visit(*this);
  58. }
  59. void NodeVisitor::visit(const AST::CastToList* node)
  60. {
  61. if (node->inner())
  62. node->inner()->visit(*this);
  63. }
  64. void NodeVisitor::visit(const AST::CloseFdRedirection*)
  65. {
  66. }
  67. void NodeVisitor::visit(const AST::CommandLiteral*)
  68. {
  69. }
  70. void NodeVisitor::visit(const AST::Comment*)
  71. {
  72. }
  73. void NodeVisitor::visit(const AST::ContinuationControl*)
  74. {
  75. }
  76. void NodeVisitor::visit(const AST::DynamicEvaluate* node)
  77. {
  78. node->inner()->visit(*this);
  79. }
  80. void NodeVisitor::visit(const AST::DoubleQuotedString* node)
  81. {
  82. if (node->inner())
  83. node->inner()->visit(*this);
  84. }
  85. void NodeVisitor::visit(const AST::Fd2FdRedirection*)
  86. {
  87. }
  88. void NodeVisitor::visit(const AST::FunctionDeclaration* node)
  89. {
  90. if (node->block())
  91. node->block()->visit(*this);
  92. }
  93. void NodeVisitor::visit(const AST::ForLoop* node)
  94. {
  95. if (node->iterated_expression())
  96. node->iterated_expression()->visit(*this);
  97. if (node->block())
  98. node->block()->visit(*this);
  99. }
  100. void NodeVisitor::visit(const AST::Glob*)
  101. {
  102. }
  103. void NodeVisitor::visit(const AST::HistoryEvent*)
  104. {
  105. }
  106. void NodeVisitor::visit(const AST::Execute* node)
  107. {
  108. node->command()->visit(*this);
  109. }
  110. void NodeVisitor::visit(const AST::IfCond* node)
  111. {
  112. node->condition()->visit(*this);
  113. if (node->true_branch())
  114. node->true_branch()->visit(*this);
  115. if (node->false_branch())
  116. node->false_branch()->visit(*this);
  117. }
  118. void NodeVisitor::visit(const AST::ImmediateExpression* node)
  119. {
  120. for (auto& node : node->arguments())
  121. node.visit(*this);
  122. }
  123. void NodeVisitor::visit(const AST::Join* node)
  124. {
  125. node->left()->visit(*this);
  126. node->right()->visit(*this);
  127. }
  128. void NodeVisitor::visit(const AST::MatchExpr* node)
  129. {
  130. node->matched_expr()->visit(*this);
  131. for (auto& entry : node->entries()) {
  132. for (auto& option : entry.options)
  133. option.visit(*this);
  134. if (entry.body)
  135. entry.body->visit(*this);
  136. }
  137. }
  138. void NodeVisitor::visit(const AST::Or* node)
  139. {
  140. node->left()->visit(*this);
  141. node->right()->visit(*this);
  142. }
  143. void NodeVisitor::visit(const AST::Pipe* node)
  144. {
  145. node->left()->visit(*this);
  146. node->right()->visit(*this);
  147. }
  148. void NodeVisitor::visit(const AST::Range* node)
  149. {
  150. node->start()->visit(*this);
  151. node->end()->visit(*this);
  152. }
  153. void NodeVisitor::visit(const AST::ReadRedirection* node)
  154. {
  155. visit(static_cast<const AST::PathRedirectionNode*>(node));
  156. }
  157. void NodeVisitor::visit(const AST::ReadWriteRedirection* node)
  158. {
  159. visit(static_cast<const AST::PathRedirectionNode*>(node));
  160. }
  161. void NodeVisitor::visit(const AST::Sequence* node)
  162. {
  163. for (auto& entry : node->entries())
  164. entry.visit(*this);
  165. }
  166. void NodeVisitor::visit(const AST::Subshell* node)
  167. {
  168. if (node->block())
  169. node->block()->visit(*this);
  170. }
  171. void NodeVisitor::visit(const AST::SimpleVariable*)
  172. {
  173. }
  174. void NodeVisitor::visit(const AST::SpecialVariable*)
  175. {
  176. }
  177. void NodeVisitor::visit(const AST::Juxtaposition* node)
  178. {
  179. node->left()->visit(*this);
  180. node->right()->visit(*this);
  181. }
  182. void NodeVisitor::visit(const AST::StringLiteral*)
  183. {
  184. }
  185. void NodeVisitor::visit(const AST::StringPartCompose* node)
  186. {
  187. node->left()->visit(*this);
  188. node->right()->visit(*this);
  189. }
  190. void NodeVisitor::visit(const AST::SyntaxError*)
  191. {
  192. }
  193. void NodeVisitor::visit(const AST::SyntheticNode*)
  194. {
  195. }
  196. void NodeVisitor::visit(const AST::Tilde*)
  197. {
  198. }
  199. void NodeVisitor::visit(const AST::VariableDeclarations* node)
  200. {
  201. for (auto& entry : node->variables()) {
  202. entry.name->visit(*this);
  203. entry.value->visit(*this);
  204. }
  205. }
  206. void NodeVisitor::visit(const AST::WriteAppendRedirection* node)
  207. {
  208. visit(static_cast<const AST::PathRedirectionNode*>(node));
  209. }
  210. void NodeVisitor::visit(const AST::WriteRedirection* node)
  211. {
  212. visit(static_cast<const AST::PathRedirectionNode*>(node));
  213. }
  214. }