# HG changeset patch # User John W. Eaton # Date 1492707152 14400 # Node ID 872f42fb26dcc9bd1c74cd2a65bd56723a0ebb1b # Parent 50fc8edb007b292a134a78de92d1bf093e9e7447 let walker visit tree_boolean and tree_compound_binary expressions directly * pt-walk.cc: New file. * module.mk: Update * pt-walk.h, pt-walk.cc (tree_walker::visit_boolean_expression, tree_walker::visit_compound_binary_expression): New methods. * pt-binop.h, pt-binop.cc (tree_boolean_expression::accept): New function. * pt-cbinop.h, pt-cbinop.cc (tree_compound_binary_expression::accept): Likewise. diff -r 50fc8edb007b -r 872f42fb26dc libinterp/parse-tree/module.mk --- a/libinterp/parse-tree/module.mk Thu Apr 20 12:27:35 2017 -0400 +++ b/libinterp/parse-tree/module.mk Thu Apr 20 12:52:32 2017 -0400 @@ -81,6 +81,7 @@ libinterp/parse-tree/pt-select.cc \ libinterp/parse-tree/pt-stmt.cc \ libinterp/parse-tree/pt-unop.cc \ + libinterp/parse-tree/pt-walk.cc \ libinterp/parse-tree/pt.cc \ libinterp/parse-tree/token.cc diff -r 50fc8edb007b -r 872f42fb26dc libinterp/parse-tree/pt-binop.cc --- a/libinterp/parse-tree/pt-binop.cc Thu Apr 20 12:27:35 2017 -0400 +++ b/libinterp/parse-tree/pt-binop.cc Thu Apr 20 12:52:32 2017 -0400 @@ -255,4 +255,10 @@ return new_be; } + + void + tree_boolean_expression::accept (tree_walker& tw) + { + tw.visit_boolean_expression (*this); + } } diff -r 50fc8edb007b -r 872f42fb26dc libinterp/parse-tree/pt-binop.h --- a/libinterp/parse-tree/pt-binop.h Thu Apr 20 12:27:35 2017 -0400 +++ b/libinterp/parse-tree/pt-binop.h Thu Apr 20 12:52:32 2017 -0400 @@ -176,6 +176,8 @@ tree_expression *dup (symbol_table::scope_id scope, symbol_table::context_id context) const; + void accept (tree_walker& tw); + private: // The type of the expression. diff -r 50fc8edb007b -r 872f42fb26dc libinterp/parse-tree/pt-cbinop.cc --- a/libinterp/parse-tree/pt-cbinop.cc Thu Apr 20 12:27:35 2017 -0400 +++ b/libinterp/parse-tree/pt-cbinop.cc Thu Apr 20 12:52:32 2017 -0400 @@ -239,4 +239,10 @@ return ret; } + + void + tree_compound_binary_expression::accept (tree_walker& tw) + { + tw.visit_compound_binary_expression (*this); + } } diff -r 50fc8edb007b -r 872f42fb26dc libinterp/parse-tree/pt-cbinop.h --- a/libinterp/parse-tree/pt-cbinop.h Thu Apr 20 12:27:35 2017 -0400 +++ b/libinterp/parse-tree/pt-cbinop.h Thu Apr 20 12:52:32 2017 -0400 @@ -61,6 +61,8 @@ octave_value_list rvalue (int nargout); + void accept (tree_walker& tw); + private: tree_expression *op_lhs; diff -r 50fc8edb007b -r 872f42fb26dc libinterp/parse-tree/pt-walk.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libinterp/parse-tree/pt-walk.cc Thu Apr 20 12:52:32 2017 -0400 @@ -0,0 +1,44 @@ +/* + +Copyright (C) 2017 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3 of the License, or +(at your option) any later version. + +Octave is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, see +. + +*/ + +#if defined (HAVE_CONFIG_H) +# include "config.h" +#endif + +#include "pt-binop.h" +#include "pt-cbinop.h" +#include "pt-walk.h" + +namespace octave +{ + void + tree_walker::visit_boolean_expression (tree_boolean_expression& expr) + { + visit_binary_expression (expr); + } + + void + tree_walker::visit_compound_binary_expression (tree_compound_binary_expression& expr) + { + visit_binary_expression (expr); + } +} diff -r 50fc8edb007b -r 872f42fb26dc libinterp/parse-tree/pt-walk.h --- a/libinterp/parse-tree/pt-walk.h Thu Apr 20 12:27:35 2017 -0400 +++ b/libinterp/parse-tree/pt-walk.h Thu Apr 20 12:52:32 2017 -0400 @@ -30,9 +30,18 @@ namespace octave { + // No separate visitor needed + // Base classes only, so no need to include them. + // + // class tree_array_list + // class tree_unary_expression + // class tree_black_hole + class tree_anon_fcn_handle; class tree_argument_list; class tree_binary_expression; + class tree_boolean_expression; + class tree_compound_binary_expression; class tree_break_command; class tree_colon_expression; class tree_continue_command; @@ -115,6 +124,12 @@ visit_binary_expression (tree_binary_expression&) = 0; virtual void + visit_boolean_expression (tree_boolean_expression& expr); + + virtual void + visit_compound_binary_expression (tree_compound_binary_expression& expr); + + virtual void visit_break_command (tree_break_command&) = 0; virtual void