Line data Source code
1 : // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 : // for details. All rights reserved. Use of this source code is governed by a
3 : // BSD-style license that can be found in the LICENSE file.
4 :
5 : import 'ast.dart';
6 :
7 : /// The interface for visitors of the boolean selector AST.
8 : abstract class Visitor<T> {
9 : T visitVariable(VariableNode node);
10 : T visitNot(NotNode node);
11 : T visitOr(OrNode node);
12 : T visitAnd(AndNode node);
13 : T visitConditional(ConditionalNode node);
14 : }
15 :
16 : /// An abstract superclass for side-effect-based visitors.
17 : ///
18 : /// The default implementations of this visitor's methods just traverse the AST
19 : /// and do nothing with it.
20 : abstract class RecursiveVisitor implements Visitor {
21 0 : const RecursiveVisitor();
22 :
23 : void visitVariable(VariableNode node) {}
24 :
25 : void visitNot(NotNode node) {
26 0 : node.child.accept(this);
27 : }
28 :
29 : void visitOr(OrNode node) {
30 0 : node.left.accept(this);
31 0 : node.right.accept(this);
32 : }
33 :
34 : void visitAnd(AndNode node) {
35 0 : node.left.accept(this);
36 0 : node.right.accept(this);
37 : }
38 :
39 : void visitConditional(ConditionalNode node) {
40 0 : node.condition.accept(this);
41 0 : node.whenTrue.accept(this);
42 0 : node.whenFalse.accept(this);
43 : }
44 : }
|