NodeVisitor.cpp 5.6 KB

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