diff libinterp/parse-tree/pt-colon.cc @ 23655:bbcc1e08aaed

improve colon expression construction and avoid possible memory leak Don't allow errors to be thrown during colon expression construction. * pt-colon.h, pt-colon.cc (tree_colon_expression::tree_colon_expression): Construct either two- or three-element expressions. (tree_colon_expression::append): Delete. (tree_colon_expression::line, tree_colon_expression::colum): Delete. * parse.h, oct-parse.in.yy (base_parser::make_colon_expression): New function. (base_parser::finish_colon_expression): Delete. (colon_expr1): Delete non-terminal (tree_colon_expression_type): Delete. (colon_expr): Construct two- or three-element expressions only. (simple_expr): Handle single oper_expr separately here.
author John W. Eaton <jwe@octave.org>
date Tue, 20 Jun 2017 10:25:54 -0400
parents 214cb58ccc1c
children 980f39c3ab90
line wrap: on
line diff
--- a/libinterp/parse-tree/pt-colon.cc	Tue Jun 20 09:28:48 2017 -0400
+++ b/libinterp/parse-tree/pt-colon.cc	Tue Jun 20 10:25:54 2017 -0400
@@ -24,79 +24,20 @@
 #  include "config.h"
 #endif
 
-#include "error.h"
-#include "ovl.h"
-#include "pager.h"
-#include "ov.h"
-#include "pt-bp.h"
 #include "pt-colon.h"
-#include "pt-walk.h"
 
 namespace octave
 {
   // Colon expressions.
 
-  tree_colon_expression *
-  tree_colon_expression::append (tree_expression *t)
-  {
-    tree_colon_expression *retval = nullptr;
-
-    if (! op_base)
-      error ("invalid colon expression");
-
-    if (op_limit)
-      {
-        if (op_increment)
-          error ("invalid colon expression");
-
-        // Stupid syntax:
-        //
-        // base : limit
-        // base : increment : limit
-
-        op_increment = op_limit;
-        op_limit = t;
-      }
-    else
-      op_limit = t;
-
-    retval = this;
-
-    return retval;
-  }
-
-  void
-  tree_colon_expression::eval_error (const std::string& s) const
-  {
-    error ("%s", s.c_str ());
-  }
-
-  int
-  tree_colon_expression::line (void) const
-  {
-    return (op_base ? op_base->line ()
-            : (op_increment ? op_increment->line ()
-               : (op_limit ? op_limit->line ()
-                  : -1)));
-  }
-
-  int
-  tree_colon_expression::column (void) const
-  {
-    return (op_base ? op_base->column ()
-            : (op_increment ? op_increment->column ()
-               : (op_limit ? op_limit->column ()
-                  : -1)));
-  }
-
   tree_expression *
   tree_colon_expression::dup (symbol_table::scope& scope) const
   {
-    tree_colon_expression *new_ce = new
-      tree_colon_expression (op_base ? op_base->dup (scope) : 0,
-                             op_limit ? op_limit->dup (scope) : 0,
-                             op_increment ? op_increment->dup (scope) : 0,
-                             line (), column ());
+    tree_colon_expression *new_ce
+      = new tree_colon_expression (op_base ? op_base->dup (scope) : 0,
+                                   op_limit ? op_limit->dup (scope) : 0,
+                                   op_increment ? op_increment->dup (scope) : 0,
+                                   line (), column ());
 
     new_ce->copy_base (*new_ce);