Mercurial > octave
changeset 23424:872f42fb26dc
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.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 20 Apr 2017 12:52:32 -0400 |
parents | 50fc8edb007b |
children | 7dfa3bc8e3d5 |
files | libinterp/parse-tree/module.mk libinterp/parse-tree/pt-binop.cc libinterp/parse-tree/pt-binop.h libinterp/parse-tree/pt-cbinop.cc libinterp/parse-tree/pt-cbinop.h libinterp/parse-tree/pt-walk.cc libinterp/parse-tree/pt-walk.h |
diffstat | 7 files changed, 76 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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); + } }
--- 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.
--- 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); + } }
--- 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;
--- /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 +<http://www.gnu.org/licenses/>. + +*/ + +#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); + } +}
--- 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