NodeVisitor.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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 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::CastToCommand* node)
  51. {
  52. node->inner()->visit(*this);
  53. }
  54. void NodeVisitor::visit(const AST::CastToList* node)
  55. {
  56. if (node->inner())
  57. node->inner()->visit(*this);
  58. }
  59. void NodeVisitor::visit(const AST::CloseFdRedirection*)
  60. {
  61. }
  62. void NodeVisitor::visit(const AST::CommandLiteral*)
  63. {
  64. }
  65. void NodeVisitor::visit(const AST::Comment*)
  66. {
  67. }
  68. void NodeVisitor::visit(const AST::DynamicEvaluate* node)
  69. {
  70. node->inner()->visit(*this);
  71. }
  72. void NodeVisitor::visit(const AST::DoubleQuotedString* node)
  73. {
  74. if (node->inner())
  75. node->inner()->visit(*this);
  76. }
  77. void NodeVisitor::visit(const AST::Fd2FdRedirection*)
  78. {
  79. }
  80. void NodeVisitor::visit(const AST::FunctionDeclaration* node)
  81. {
  82. if (node->block())
  83. node->block()->visit(*this);
  84. }
  85. void NodeVisitor::visit(const AST::ForLoop* node)
  86. {
  87. node->iterated_expression()->visit(*this);
  88. if (node->block())
  89. node->block()->visit(*this);
  90. }
  91. void NodeVisitor::visit(const AST::Glob*)
  92. {
  93. }
  94. void NodeVisitor::visit(const AST::Execute* node)
  95. {
  96. node->command()->visit(*this);
  97. }
  98. void NodeVisitor::visit(const AST::IfCond* node)
  99. {
  100. node->condition()->visit(*this);
  101. if (node->true_branch())
  102. node->true_branch()->visit(*this);
  103. if (node->false_branch())
  104. node->false_branch()->visit(*this);
  105. }
  106. void NodeVisitor::visit(const AST::Join* node)
  107. {
  108. node->left()->visit(*this);
  109. node->right()->visit(*this);
  110. }
  111. void NodeVisitor::visit(const AST::MatchExpr* node)
  112. {
  113. node->matched_expr()->visit(*this);
  114. for (auto& entry : node->entries()) {
  115. for (auto& option : entry.options)
  116. option.visit(*this);
  117. if (entry.body)
  118. entry.body->visit(*this);
  119. }
  120. }
  121. void NodeVisitor::visit(const AST::Or* node)
  122. {
  123. node->left()->visit(*this);
  124. node->right()->visit(*this);
  125. }
  126. void NodeVisitor::visit(const AST::Pipe* node)
  127. {
  128. node->left()->visit(*this);
  129. node->right()->visit(*this);
  130. }
  131. void NodeVisitor::visit(const AST::ReadRedirection* node)
  132. {
  133. visit(static_cast<const AST::PathRedirectionNode*>(node));
  134. }
  135. void NodeVisitor::visit(const AST::ReadWriteRedirection* node)
  136. {
  137. visit(static_cast<const AST::PathRedirectionNode*>(node));
  138. }
  139. void NodeVisitor::visit(const AST::Sequence* node)
  140. {
  141. node->left()->visit(*this);
  142. node->right()->visit(*this);
  143. }
  144. void NodeVisitor::visit(const AST::Subshell* node)
  145. {
  146. if (node->block())
  147. node->block()->visit(*this);
  148. }
  149. void NodeVisitor::visit(const AST::SimpleVariable*)
  150. {
  151. }
  152. void NodeVisitor::visit(const AST::SpecialVariable*)
  153. {
  154. }
  155. void NodeVisitor::visit(const AST::Juxtaposition* node)
  156. {
  157. node->left()->visit(*this);
  158. node->right()->visit(*this);
  159. }
  160. void NodeVisitor::visit(const AST::StringLiteral*)
  161. {
  162. }
  163. void NodeVisitor::visit(const AST::StringPartCompose* node)
  164. {
  165. node->left()->visit(*this);
  166. node->right()->visit(*this);
  167. }
  168. void NodeVisitor::visit(const AST::SyntaxError*)
  169. {
  170. }
  171. void NodeVisitor::visit(const AST::Tilde*)
  172. {
  173. }
  174. void NodeVisitor::visit(const AST::VariableDeclarations* node)
  175. {
  176. for (auto& entry : node->variables()) {
  177. entry.name->visit(*this);
  178. entry.value->visit(*this);
  179. }
  180. }
  181. void NodeVisitor::visit(const AST::WriteAppendRedirection* node)
  182. {
  183. visit(static_cast<const AST::PathRedirectionNode*>(node));
  184. }
  185. void NodeVisitor::visit(const AST::WriteRedirection* node)
  186. {
  187. visit(static_cast<const AST::PathRedirectionNode*>(node));
  188. }
  189. }