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<void> { 21 0 : const RecursiveVisitor(); 22 : 23 0 : @override 24 : void visitVariable(VariableNode node) {} 25 : 26 0 : @override 27 : void visitNot(NotNode node) { 28 0 : node.child.accept(this); 29 : } 30 : 31 0 : @override 32 : void visitOr(OrNode node) { 33 0 : node.left.accept(this); 34 0 : node.right.accept(this); 35 : } 36 : 37 0 : @override 38 : void visitAnd(AndNode node) { 39 0 : node.left.accept(this); 40 0 : node.right.accept(this); 41 : } 42 : 43 0 : @override 44 : void visitConditional(ConditionalNode node) { 45 0 : node.condition.accept(this); 46 0 : node.whenTrue.accept(this); 47 0 : node.whenFalse.accept(this); 48 : } 49 : }