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):
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_ContinueNode(self, node: mparser.ContinueNode) -> None:
40        self.visit_default_func(node)
41
42    def visit_BreakNode(self, node: mparser.BreakNode) -> None:
43        self.visit_default_func(node)
44
45    def visit_ArrayNode(self, node: mparser.ArrayNode) -> None:
46        self.visit_default_func(node)
47        node.args.accept(self)
48
49    def visit_DictNode(self, node: mparser.DictNode) -> None:
50        self.visit_default_func(node)
51        node.args.accept(self)
52
53    def visit_EmptyNode(self, node: mparser.EmptyNode) -> None:
54        self.visit_default_func(node)
55
56    def visit_OrNode(self, node: mparser.OrNode) -> None:
57        self.visit_default_func(node)
58        node.left.accept(self)
59        node.right.accept(self)
60
61    def visit_AndNode(self, node: mparser.AndNode) -> None:
62        self.visit_default_func(node)
63        node.left.accept(self)
64        node.right.accept(self)
65
66    def visit_ComparisonNode(self, node: mparser.ComparisonNode) -> None:
67        self.visit_default_func(node)
68        node.left.accept(self)
69        node.right.accept(self)
70
71    def visit_ArithmeticNode(self, node: mparser.ArithmeticNode) -> None:
72        self.visit_default_func(node)
73        node.left.accept(self)
74        node.right.accept(self)
75
76    def visit_NotNode(self, node: mparser.NotNode) -> None:
77        self.visit_default_func(node)
78        node.value.accept(self)
79
80    def visit_CodeBlockNode(self, node: mparser.CodeBlockNode) -> None:
81        self.visit_default_func(node)
82        for i in node.lines:
83            i.accept(self)
84
85    def visit_IndexNode(self, node: mparser.IndexNode) -> None:
86        self.visit_default_func(node)
87        node.iobject.accept(self)
88        node.index.accept(self)
89
90    def visit_MethodNode(self, node: mparser.MethodNode) -> None:
91        self.visit_default_func(node)
92        node.source_object.accept(self)
93        node.args.accept(self)
94
95    def visit_FunctionNode(self, node: mparser.FunctionNode) -> None:
96        self.visit_default_func(node)
97        node.args.accept(self)
98
99    def visit_AssignmentNode(self, node: mparser.AssignmentNode) -> None:
100        self.visit_default_func(node)
101        node.value.accept(self)
102
103    def visit_PlusAssignmentNode(self, node: mparser.PlusAssignmentNode) -> None:
104        self.visit_default_func(node)
105        node.value.accept(self)
106
107    def visit_ForeachClauseNode(self, node: mparser.ForeachClauseNode) -> None:
108        self.visit_default_func(node)
109        node.items.accept(self)
110        node.block.accept(self)
111
112    def visit_IfClauseNode(self, node: mparser.IfClauseNode) -> None:
113        self.visit_default_func(node)
114        for i in node.ifs:
115            i.accept(self)
116        node.elseblock.accept(self)
117
118    def visit_UMinusNode(self, node: mparser.UMinusNode) -> None:
119        self.visit_default_func(node)
120        node.value.accept(self)
121
122    def visit_IfNode(self, node: mparser.IfNode) -> None:
123        self.visit_default_func(node)
124        node.condition.accept(self)
125        node.block.accept(self)
126
127    def visit_TernaryNode(self, node: mparser.TernaryNode) -> None:
128        self.visit_default_func(node)
129        node.condition.accept(self)
130        node.trueblock.accept(self)
131        node.falseblock.accept(self)
132
133    def visit_ArgumentNode(self, node: mparser.ArgumentNode) -> None:
134        self.visit_default_func(node)
135        for i in node.arguments:
136            i.accept(self)
137        for key, val in node.kwargs.items():
138            key.accept(self)
139            val.accept(self)
140