NodeVisitor.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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::Join* node)
  119. {
  120. node->left()->visit(*this);
  121. node->right()->visit(*this);
  122. }
  123. void NodeVisitor::visit(const AST::MatchExpr* node)
  124. {
  125. node->matched_expr()->visit(*this);
  126. for (auto& entry : node->entries()) {
  127. for (auto& option : entry.options)
  128. option.visit(*this);
  129. if (entry.body)
  130. entry.body->visit(*this);
  131. }
  132. }
  133. void NodeVisitor::visit(const AST::Or* node)
  134. {
  135. node->left()->visit(*this);
  136. node->right()->visit(*this);
  137. }
  138. void NodeVisitor::visit(const AST::Pipe* node)
  139. {
  140. node->left()->visit(*this);
  141. node->right()->visit(*this);
  142. }
  143. void NodeVisitor::visit(const AST::Range* node)
  144. {
  145. node->start()->visit(*this);
  146. node->end()->visit(*this);
  147. }
  148. void NodeVisitor::visit(const AST::ReadRedirection* node)
  149. {
  150. visit(static_cast<const AST::PathRedirectionNode*>(node));
  151. }
  152. void NodeVisitor::visit(const AST::ReadWriteRedirection* node)
  153. {
  154. visit(static_cast<const AST::PathRedirectionNode*>(node));
  155. }
  156. void NodeVisitor::visit(const AST::Sequence* node)
  157. {
  158. for (auto& entry : node->entries())
  159. entry.visit(*this);
  160. }
  161. void NodeVisitor::visit(const AST::Subshell* node)
  162. {
  163. if (node->block())
  164. node->block()->visit(*this);
  165. }
  166. void NodeVisitor::visit(const AST::SimpleVariable*)
  167. {
  168. }
  169. void NodeVisitor::visit(const AST::SpecialVariable*)
  170. {
  171. }
  172. void NodeVisitor::visit(const AST::Juxtaposition* node)
  173. {
  174. node->left()->visit(*this);
  175. node->right()->visit(*this);
  176. }
  177. void NodeVisitor::visit(const AST::StringLiteral*)
  178. {
  179. }
  180. void NodeVisitor::visit(const AST::StringPartCompose* node)
  181. {
  182. node->left()->visit(*this);
  183. node->right()->visit(*this);
  184. }
  185. void NodeVisitor::visit(const AST::SyntaxError*)
  186. {
  187. }
  188. void NodeVisitor::visit(const AST::Tilde*)
  189. {
  190. }
  191. void NodeVisitor::visit(const AST::VariableDeclarations* node)
  192. {
  193. for (auto& entry : node->variables()) {
  194. entry.name->visit(*this);
  195. entry.value->visit(*this);
  196. }
  197. }
  198. void NodeVisitor::visit(const AST::WriteAppendRedirection* node)
  199. {
  200. visit(static_cast<const AST::PathRedirectionNode*>(node));
  201. }
  202. void NodeVisitor::visit(const AST::WriteRedirection* node)
  203. {
  204. visit(static_cast<const AST::PathRedirectionNode*>(node));
  205. }
  206. }