changeset 24564:07876b7127bf

reorganize binding to ans in evaluator for clarity * pt-eval.cc (tree_evaluator::visit_statement): Evaluate expression first, then decide whether to bind to ans.
author John W. Eaton <jwe@octave.org>
date Mon, 08 Jan 2018 15:51:52 -0500
parents 8f2c479eb125
children dbec1e04f499
files libinterp/parse-tree/pt-eval.cc
diffstat 1 files changed, 23 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/parse-tree/pt-eval.cc	Mon Jan 08 13:25:10 2018 -0500
+++ b/libinterp/parse-tree/pt-eval.cc	Mon Jan 08 15:51:52 2018 -0500
@@ -2280,29 +2280,31 @@
                 // evaluate the expression and that should take care of
                 // everything, binding ans as necessary?
 
-                bool do_bind_ans = false;
-
-                if (expr->is_identifier ())
+                octave_value tmp_result = evaluate (expr, 0);
+
+                if (tmp_result.is_defined ())
                   {
-                    symbol_scope scope = get_current_scope ();
-
-                    symbol_record::context_id context = scope.current_context ();
-
-                    tree_identifier *id = dynamic_cast<tree_identifier *> (expr);
-
-                    do_bind_ans = (! id->is_variable (context));
+                    bool do_bind_ans = false;
+
+                    if (expr->is_identifier ())
+                      {
+                        symbol_scope scope = get_current_scope ();
+
+                        symbol_record::context_id context
+                          = scope.current_context ();
+
+                        tree_identifier *id
+                          = dynamic_cast<tree_identifier *> (expr);
+
+                        do_bind_ans = (! id->is_variable (context));
+                      }
+                    else
+                      do_bind_ans = (! expr->is_assignment_expression ());
+
+                    if (do_bind_ans)
+                      bind_ans (tmp_result, expr->print_result ()
+                                && statement_printing_enabled ());
                   }
-                else
-                  do_bind_ans = (! expr->is_assignment_expression ());
-
-                octave_value tmp_result = evaluate (expr, 0);
-
-                if (do_bind_ans && tmp_result.is_defined ())
-                  bind_ans (tmp_result, expr->print_result ()
-                            && statement_printing_enabled ());
-
-                //              if (tmp_result.is_defined ())
-                //                result_values(0) = tmp_result;
               }
           }
         catch (const std::bad_alloc&)