1# Copyright 2019 The Meson development team 2 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6 7# http://www.apache.org/licenses/LICENSE-2.0 8 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15# This class contains the basic functionality needed to run any interpreter 16# or an interpreter-based tool 17 18from .. import mparser 19 20class AstVisitor: 21 def __init__(self) -> None: 22 pass 23 24 def visit_default_func(self, node: mparser.BaseNode) -> None: 25 pass 26 27 def visit_BooleanNode(self, node: mparser.BooleanNode) -> None: 28 self.visit_default_func(node) 29 30 def visit_IdNode(self, node: mparser.IdNode) -> None: 31 self.visit_default_func(node) 32 33 def visit_NumberNode(self, node: mparser.NumberNode) -> None: 34 self.visit_default_func(node) 35 36 def visit_StringNode(self, node: mparser.StringNode) -> None: 37 self.visit_default_func(node) 38 39 def visit_FormatStringNode(self, node: mparser.FormatStringNode) -> None: 40 self.visit_default_func(node) 41 42 def visit_ContinueNode(self, node: mparser.ContinueNode) -> None: 43 self.visit_default_func(node) 44 45 def visit_BreakNode(self, node: mparser.BreakNode) -> None: 46 self.visit_default_func(node) 47 48 def visit_ArrayNode(self, node: mparser.ArrayNode) -> None: 49 self.visit_default_func(node) 50 node.args.accept(self) 51 52 def visit_DictNode(self, node: mparser.DictNode) -> None: 53 self.visit_default_func(node) 54 node.args.accept(self) 55 56 def visit_EmptyNode(self, node: mparser.EmptyNode) -> None: 57 self.visit_default_func(node) 58 59 def visit_OrNode(self, node: mparser.OrNode) -> None: 60 self.visit_default_func(node) 61 node.left.accept(self) 62 node.right.accept(self) 63 64 def visit_AndNode(self, node: mparser.AndNode) -> None: 65 self.visit_default_func(node) 66 node.left.accept(self) 67 node.right.accept(self) 68 69 def visit_ComparisonNode(self, node: mparser.ComparisonNode) -> None: 70 self.visit_default_func(node) 71 node.left.accept(self) 72 node.right.accept(self) 73 74 def visit_ArithmeticNode(self, node: mparser.ArithmeticNode) -> None: 75 self.visit_default_func(node) 76 node.left.accept(self) 77 node.right.accept(self) 78 79 def visit_NotNode(self, node: mparser.NotNode) -> None: 80 self.visit_default_func(node) 81 node.value.accept(self) 82 83 def visit_CodeBlockNode(self, node: mparser.CodeBlockNode) -> None: 84 self.visit_default_func(node) 85 for i in node.lines: 86 i.accept(self) 87 88 def visit_IndexNode(self, node: mparser.IndexNode) -> None: 89 self.visit_default_func(node) 90 node.iobject.accept(self) 91 node.index.accept(self) 92 93 def visit_MethodNode(self, node: mparser.MethodNode) -> None: 94 self.visit_default_func(node) 95 node.source_object.accept(self) 96 node.args.accept(self) 97 98 def visit_FunctionNode(self, node: mparser.FunctionNode) -> None: 99 self.visit_default_func(node) 100 node.args.accept(self) 101 102 def visit_AssignmentNode(self, node: mparser.AssignmentNode) -> None: 103 self.visit_default_func(node) 104 node.value.accept(self) 105 106 def visit_PlusAssignmentNode(self, node: mparser.PlusAssignmentNode) -> None: 107 self.visit_default_func(node) 108 node.value.accept(self) 109 110 def visit_ForeachClauseNode(self, node: mparser.ForeachClauseNode) -> None: 111 self.visit_default_func(node) 112 node.items.accept(self) 113 node.block.accept(self) 114 115 def visit_IfClauseNode(self, node: mparser.IfClauseNode) -> None: 116 self.visit_default_func(node) 117 for i in node.ifs: 118 i.accept(self) 119 node.elseblock.accept(self) 120 121 def visit_UMinusNode(self, node: mparser.UMinusNode) -> None: 122 self.visit_default_func(node) 123 node.value.accept(self) 124 125 def visit_IfNode(self, node: mparser.IfNode) -> None: 126 self.visit_default_func(node) 127 node.condition.accept(self) 128 node.block.accept(self) 129 130 def visit_TernaryNode(self, node: mparser.TernaryNode) -> None: 131 self.visit_default_func(node) 132 node.condition.accept(self) 133 node.trueblock.accept(self) 134 node.falseblock.accept(self) 135 136 def visit_ArgumentNode(self, node: mparser.ArgumentNode) -> None: 137 self.visit_default_func(node) 138 for i in node.arguments: 139 i.accept(self) 140 for key, val in node.kwargs.items(): 141 key.accept(self) 142 val.accept(self) 143