changeset 4173:2aea727f516f

[project @ 2002-11-12 23:05:40 by jwe]
author jwe
date Tue, 12 Nov 2002 23:05:41 +0000
parents 2e94b2abfe6d
children aabb8307021f
files src/ChangeLog src/ov-usr-fcn.cc src/parse.y src/pt-bp.cc src/pt-bp.h src/pt-check.cc src/pt-check.h src/pt-except.cc src/pt-jump.cc src/pt-jump.h src/pt-loop.cc src/pt-pr-code.cc src/pt-pr-code.h src/pt-stmt.cc src/pt-walk.h src/toplev.cc
diffstat 16 files changed, 168 insertions(+), 138 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Tue Nov 12 21:14:04 2002 +0000
+++ b/src/ChangeLog	Tue Nov 12 23:05:41 2002 +0000
@@ -1,5 +1,16 @@
 2002-11-12  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
+	* pt-jump.h, pt-jump.cc (tree_break_expression,
+	tree_continue_expression, tree_return_expression): Rename from
+	tree_break_command, tree_continue_command, tree_return_command.
+	Implement as expressions that return TRUE instead of commands.
+	Change all uses.
+	* parse.y (make_break_expression, make_continue_expression,
+	make_return_expression): Rename from make_break_command,
+	make_continue_command, make_return_command.  Change all uses.
+	(jump_expr): Rename from jump_command, type is now expression.
+	Use in simple_expr, not command.	
+
 	* toplev.cc (octave_initialized): New global variable.
 	(main_loop): Set it to true here.
 	* sighandlers.cc (sigint_handler): Exit immediately if we have not
--- a/src/ov-usr-fcn.cc	Tue Nov 12 21:14:04 2002 +0000
+++ b/src/ov-usr-fcn.cc	Tue Nov 12 23:05:41 2002 +0000
@@ -466,11 +466,11 @@
     if (echo_commands)
       print_code_function_trailer ();
 
-    if (tree_return_command::returning)
-      tree_return_command::returning = 0;
+    if (tree_return_expression::returning)
+      tree_return_expression::returning = 0;
 
-    if (tree_break_command::breaking)
-      tree_break_command::breaking--;
+    if (tree_break_expression::breaking)
+      tree_break_expression::breaking--;
 
     if (error_state)
       {
--- a/src/parse.y	Tue Nov 12 21:14:04 2002 +0000
+++ b/src/parse.y	Tue Nov 12 23:05:41 2002 +0000
@@ -219,17 +219,17 @@
 		  tree_expression *expr, tree_statement_list *body,
 		  token *end_tok, octave_comment_list *lc);
 
-// Build a break command.
-static tree_command *
-make_break_command (token *break_tok);
-
-// Build a continue command.
-static tree_command *
-make_continue_command (token *continue_tok);
-
-// Build a return command.
-static tree_command *
-make_return_command (token *return_tok);
+// Build a break expression.
+static tree_expression *
+make_break_expression (token *break_tok);
+
+// Build a continue expression.
+static tree_expression *
+make_continue_expression (token *continue_tok);
+
+// Build a return expression.
+static tree_expression *
+make_return_expression (token *return_tok);
 
 // Start an if command.
 static tree_if_command_list *
@@ -418,8 +418,9 @@
 %type <tree_matrix_type> matrix_rows matrix_rows1
 %type <tree_cell_type> cell_rows cell_rows1
 %type <tree_expression_type> title matrix cell
-%type <tree_expression_type> primary_expr postfix_expr prefix_expr binary_expr
-%type <tree_expression_type> simple_expr colon_expr assign_expr expression
+%type <tree_expression_type> primary_expr postfix_expr prefix_expr
+%type <tree_expression_type> binary_expr simple_expr colon_expr
+%type <tree_expression_type> assign_expr jump_expr expression
 %type <tree_identifier_type> identifier
 %type <octave_user_function_type> function1 function2 function3
 %type <tree_index_expression_type> word_list_cmd
@@ -429,7 +430,7 @@
 %type <tree_parameter_list_type> param_list param_list1
 %type <tree_parameter_list_type> return_list return_list1
 %type <tree_command_type> command select_command loop_command
-%type <tree_command_type> jump_command except_command function
+%type <tree_command_type> except_command function
 %type <tree_if_command_type> if_command
 %type <tree_if_clause_type> elseif_clause else_clause
 %type <tree_if_command_list_type> if_cmd_list1 if_cmd_list
@@ -786,6 +787,8 @@
 
 simple_expr	: colon_expr
 		  { $$ = $1; }
+		| jump_expr
+		  { $$ = $1; }
 		| simple_expr LSHIFT simple_expr
 		  { $$ = make_binary_op (LSHIFT, $1, $2, $3); }
 		| simple_expr RSHIFT simple_expr
@@ -891,8 +894,6 @@
 		  { $$ = $1; }
 		| loop_command
 		  { $$ = $1; }
-		| jump_command
-		  { $$ = $1; }
 		| except_command
 		  { $$ = $1; }
 		| function
@@ -1041,19 +1042,19 @@
 // Jumping
 // =======
 
-jump_command	: BREAK
+jump_expr	: BREAK
 		  {
-		    if (! ($$ = make_break_command ($1)))
+		    if (! ($$ = make_break_expression ($1)))
 		      ABORT_PARSE;
 		  }
 		| CONTINUE
 		  {
-		    if (! ($$ = make_continue_command ($1)))
+		    if (! ($$ = make_continue_expression ($1)))
 		      ABORT_PARSE;
 		  }
 		| FUNC_RET
 		  {
-		    if (! ($$ = make_return_command ($1)))
+		    if (! ($$ = make_return_expression ($1)))
 		      ABORT_PARSE;
 		  }
 		;
@@ -2243,12 +2244,12 @@
   return retval;
 }
 
-// Build a break command.
-
-static tree_command *
-make_break_command (token *break_tok)
+// Build a break expression.
+
+static tree_expression *
+make_break_expression (token *break_tok)
 {
-  tree_command *retval = 0;
+  tree_expression *retval = 0;
 
   int l = break_tok->line ();
   int c = break_tok->column ();
@@ -2256,46 +2257,46 @@
   if (lexer_flags.looping || lexer_flags.defining_func
       || reading_script_file || evaluating_function_body
       || evaluating_looping_command)
-    retval = new tree_break_command (l, c);
+    retval = new tree_break_expression (l, c);
   else
-    retval = new tree_no_op_command ("break", l, c);
+    yyerror ("invalid use of break");
 
   return retval;
 }
 
-// Build a continue command.
-
-static tree_command *
-make_continue_command (token *continue_tok)
+// Build a continue expression.
+
+static tree_expression *
+make_continue_expression (token *continue_tok)
 {
-  tree_command *retval = 0;
+  tree_expression *retval = 0;
 
   int l = continue_tok->line ();
   int c = continue_tok->column ();
 
   if (lexer_flags.looping || evaluating_looping_command)
-    retval = new tree_continue_command (l, c);
+    retval = new tree_continue_expression (l, c);
   else
-    retval = new tree_no_op_command ("continue", l, c);
+    yyerror ("invalid use of continue");
 
   return retval;
 }
 
-// Build a return command.
-
-static tree_command *
-make_return_command (token *return_tok)
+// Build a return expression.
+
+static tree_expression *
+make_return_expression (token *return_tok)
 {
-  tree_command *retval = 0;
+  tree_expression *retval = 0;
 
   int l = return_tok->line ();
   int c = return_tok->column ();
 
   if (lexer_flags.defining_func || reading_script_file
       || evaluating_function_body)
-    retval = new tree_return_command (l, c);
+    retval = new tree_return_expression (l, c);
   else
-    retval = new tree_no_op_command ("return", l, c);
+    yyerror ("invalid use of return");
 
   return retval;
 }
@@ -2865,14 +2866,14 @@
 
 	      OCTAVE_QUIT;
 
-	      bool quit = (tree_return_command::returning
-			   || tree_break_command::breaking);
-
-	      if (tree_return_command::returning)
-		tree_return_command::returning = 0;
-
-	      if (tree_break_command::breaking)
-		tree_break_command::breaking--;
+	      bool quit = (tree_return_expression::returning
+			   || tree_break_expression::breaking);
+
+	      if (tree_return_expression::returning)
+		tree_return_expression::returning = 0;
+
+	      if (tree_break_expression::breaking)
+		tree_break_expression::breaking--;
 
 	      if (error_state)
 		{
@@ -3558,9 +3559,9 @@
 	      command = 0;
 
 	      if (error_state
-		  || tree_return_command::returning
-		  || tree_break_command::breaking
-		  || tree_continue_command::continuing)
+		  || tree_return_expression::returning
+		  || tree_break_expression::breaking
+		  || tree_continue_expression::continuing)
 		break;
 	    }
 	  else if (parser_end_of_input)
--- a/src/pt-bp.cc	Tue Nov 12 21:14:04 2002 +0000
+++ b/src/pt-bp.cc	Tue Nov 12 23:05:41 2002 +0000
@@ -136,7 +136,7 @@
 }
 
 void 
-tree_breakpoint::visit_break_command (tree_break_command& cmd)
+tree_breakpoint::visit_break_expression (tree_break_expression& cmd)
 {
   if (found)
     return;
@@ -171,7 +171,7 @@
 }
 
 void 
-tree_breakpoint::visit_continue_command (tree_continue_command& cmd)
+tree_breakpoint::visit_continue_expression (tree_continue_expression& cmd)
 {
   if (found)
     return;
@@ -510,7 +510,7 @@
 }
 
 void 
-tree_breakpoint::visit_return_command (tree_return_command& cmd)
+tree_breakpoint::visit_return_expression (tree_return_expression& cmd)
 {
   if (found)
     return;
--- a/src/pt-bp.h	Tue Nov 12 21:14:04 2002 +0000
+++ b/src/pt-bp.h	Tue Nov 12 23:05:41 2002 +0000
@@ -53,11 +53,11 @@
 
   void visit_binary_expression (tree_binary_expression&);
 
-  void visit_break_command (tree_break_command&);
+  void visit_break_expression (tree_break_expression&);
 
   void visit_colon_expression (tree_colon_expression&);
 
-  void visit_continue_command (tree_continue_command&);
+  void visit_continue_expression (tree_continue_expression&);
 
   void visit_decl_command (tree_decl_command&);
 
@@ -111,7 +111,7 @@
 
   void visit_prefix_expression (tree_prefix_expression&);
 
-  void visit_return_command (tree_return_command&);
+  void visit_return_expression (tree_return_expression&);
 
   void visit_return_list (tree_return_list&);
 
--- a/src/pt-check.cc	Tue Nov 12 21:14:04 2002 +0000
+++ b/src/pt-check.cc	Tue Nov 12 23:05:41 2002 +0000
@@ -67,7 +67,7 @@
 }
 
 void
-tree_checker::visit_break_command (tree_break_command&)
+tree_checker::visit_break_expression (tree_break_expression&)
 {
 }
 
@@ -91,7 +91,7 @@
 }
 
 void
-tree_checker::visit_continue_command (tree_continue_command&)
+tree_checker::visit_continue_expression (tree_continue_expression&)
 {
 }
 
@@ -391,7 +391,7 @@
 }
 
 void
-tree_checker::visit_return_command (tree_return_command&)
+tree_checker::visit_return_expression (tree_return_expression&)
 {
 }
 
--- a/src/pt-check.h	Tue Nov 12 21:14:04 2002 +0000
+++ b/src/pt-check.h	Tue Nov 12 23:05:41 2002 +0000
@@ -45,11 +45,11 @@
 
   void visit_binary_expression (tree_binary_expression&);
 
-  void visit_break_command (tree_break_command&);
+  void visit_break_expression (tree_break_expression&);
 
   void visit_colon_expression (tree_colon_expression&);
 
-  void visit_continue_command (tree_continue_command&);
+  void visit_continue_expression(tree_continue_expression&);
 
   void visit_decl_command (tree_decl_command&);
 
@@ -93,7 +93,7 @@
 
   void visit_prefix_expression (tree_prefix_expression&);
 
-  void visit_return_command (tree_return_command&);
+  void visit_return_expression (tree_return_expression&);
 
   void visit_return_list (tree_return_list&);
 
--- a/src/pt-except.cc	Tue Nov 12 21:14:04 2002 +0000
+++ b/src/pt-except.cc	Tue Nov 12 23:05:41 2002 +0000
@@ -149,11 +149,11 @@
   // We don't have to worry about continue statements because they can
   // only occur in loops.
 
-  unwind_protect_int (tree_return_command::returning);
-  tree_return_command::returning = 0;
+  unwind_protect_int (tree_return_expression::returning);
+  tree_return_expression::returning = 0;
 
-  unwind_protect_int (tree_break_command::breaking);
-  tree_break_command::breaking = 0;
+  unwind_protect_int (tree_break_expression::breaking);
+  tree_break_expression::breaking = 0;
 
   if (list)
     list->eval ();
@@ -185,7 +185,7 @@
   // break in the cleanup block, the values should be reset to
   // whatever they were when the cleanup block was entered.
 
-  if (tree_break_command::breaking || tree_return_command::returning)
+  if (tree_break_expression::breaking || tree_return_expression::returning)
     {
       unwind_protect::discard ();
       unwind_protect::discard ();
--- a/src/pt-jump.cc	Tue Nov 12 21:14:04 2002 +0000
+++ b/src/pt-jump.cc	Tue Nov 12 23:05:41 2002 +0000
@@ -39,63 +39,69 @@
 // Break.
 
 // Nonzero means we're breaking out of a loop or function body.
-int tree_break_command::breaking = 0;
+int tree_break_expression::breaking = 0;
 
-void
-tree_break_command::eval (void)
+octave_value
+tree_break_expression::rvalue (void)
 {
   // Even if we have an error we should still enter debug mode.
   MAYBE_DO_BREAKPOINT;
 
   if (! error_state)
     breaking = 1;
+
+  return true;
 }
 
 void
-tree_break_command::accept (tree_walker& tw)
+tree_break_expression::accept (tree_walker& tw)
 {
-  tw.visit_break_command (*this);
+  tw.visit_break_expression (*this);
 }
 
 // Continue.
 
 // Nonzero means we're jumping to the end of a loop.
-int tree_continue_command::continuing = 0;
+int tree_continue_expression::continuing = 0;
 
-void
-tree_continue_command::eval (void)
+octave_value
+tree_continue_expression::rvalue (void)
 {
   MAYBE_DO_BREAKPOINT;
 
   if (! error_state)
     continuing = 1;
+
+  return true;
 }
 
 void
-tree_continue_command::accept (tree_walker& tw)
+tree_continue_expression::accept (tree_walker& tw)
 {
-  tw.visit_continue_command (*this);
+  tw.visit_continue_expression (*this);
 }
 
 // Return.
 
 // Nonzero means we're returning from a function.  Global because it
 // is also needed in tree-expr.cc.
-int tree_return_command::returning = 0;
+int tree_return_expression::returning = 0;
 
-void
-tree_return_command::eval (void)
+octave_value
+tree_return_expression::rvalue (void)
 {
   MAYBE_DO_BREAKPOINT;
 
   if (! error_state)
     returning = 1;
+
+  return true;
 }
 
 void
-tree_return_command::accept (tree_walker& tw)
+tree_return_expression::accept (tree_walker& tw)
 {
-  tw.visit_return_command (*this);
+  tw.visit_return_expression (*this);
 }
 
 /*
--- a/src/pt-jump.h	Tue Nov 12 21:14:04 2002 +0000
+++ b/src/pt-jump.h	Tue Nov 12 23:05:41 2002 +0000
@@ -29,21 +29,25 @@
 
 class tree_walker;
 
-#include "pt-cmd.h"
+#include "pt-exp.h"
 
 // Break.
 
 class
-tree_break_command : public tree_command
+tree_break_expression : public tree_expression
 {
 public:
 
-  tree_break_command (int l = -1, int c = -1)
-    : tree_command (l, c) { }
+  tree_break_expression (int l = -1, int c = -1)
+    : tree_expression (l, c) { }
+
+  ~tree_break_expression (void) { }
 
-  ~tree_break_command (void) { }
+  bool rvalue_ok (void) { return true; }
 
-  void eval (void);
+  octave_value rvalue (void);
+
+  octave_value_list rvalue (int nargout) { return rvalue (); }
 
   void accept (tree_walker& tw);
 
@@ -53,24 +57,28 @@
 
   // No copying!
 
-  tree_break_command (const tree_break_command&);
+  tree_break_expression (const tree_break_expression&);
 
-  tree_break_command& operator = (const tree_break_command&);
+  tree_break_expression& operator = (const tree_break_expression&);
 };
 
 // Continue.
 
 class
-tree_continue_command : public tree_command
+tree_continue_expression : public tree_expression
 {
 public:
 
-  tree_continue_command (int l = -1, int c = -1)
-    : tree_command (l, c) { }
+  tree_continue_expression (int l = -1, int c = -1)
+    : tree_expression (l, c) { }
+
+  ~tree_continue_expression (void) { }
 
-  ~tree_continue_command (void) { }
+  bool rvalue_ok (void) { return true; }
 
-  void eval (void);
+  octave_value rvalue (void);
+
+  octave_value_list rvalue (int nargout) { return rvalue (); }
 
   void accept (tree_walker& tw);
 
@@ -80,24 +88,28 @@
 
   // No copying!
 
-  tree_continue_command (const tree_continue_command&);
+  tree_continue_expression (const tree_continue_expression&);
 
-  tree_continue_command& operator = (const tree_continue_command&);
+  tree_continue_expression& operator = (const tree_continue_expression&);
 };
 
 // Return.
 
 class
-tree_return_command : public tree_command
+tree_return_expression : public tree_expression
 {
 public:
 
-  tree_return_command (int l = -1, int c = -1)
-    : tree_command (l, c) { }
+  tree_return_expression (int l = -1, int c = -1)
+    : tree_expression (l, c) { }
+
+  ~tree_return_expression (void) { }
 
-  ~tree_return_command (void) { }
+  bool rvalue_ok (void) { return true; }
 
-  void eval (void);
+  octave_value rvalue (void);
+
+  octave_value_list rvalue (int nargout) { return rvalue (); }
 
   void accept (tree_walker& tw);
 
@@ -107,9 +119,9 @@
 
   // No copying!
 
-  tree_return_command (const tree_return_command&);
+  tree_return_expression (const tree_return_expression&);
 
-  tree_return_command& operator = (const tree_return_command&);
+  tree_return_expression& operator = (const tree_return_expression&);
 };
 
 #endif
--- a/src/pt-loop.cc	Tue Nov 12 21:14:04 2002 +0000
+++ b/src/pt-loop.cc	Tue Nov 12 23:05:41 2002 +0000
@@ -56,16 +56,16 @@
 
   // Maybe handle `continue N' someday...
 
-  if (tree_continue_command::continuing)
-    tree_continue_command::continuing--;
+  if (tree_continue_expression::continuing)
+    tree_continue_expression::continuing--;
 
   bool quit = (error_state
-	       || tree_return_command::returning
-	       || tree_break_command::breaking
-	       || tree_continue_command::continuing);
+	       || tree_return_expression::returning
+	       || tree_break_expression::breaking
+	       || tree_continue_expression::continuing);
 
-  if (tree_break_command::breaking)
-    tree_break_command::breaking--;
+  if (tree_break_expression::breaking)
+    tree_break_expression::breaking--;
 
   return quit;
 }
--- a/src/pt-pr-code.cc	Tue Nov 12 21:14:04 2002 +0000
+++ b/src/pt-pr-code.cc	Tue Nov 12 23:05:41 2002 +0000
@@ -82,7 +82,7 @@
 }
 
 void
-tree_print_code::visit_break_command (tree_break_command&)
+tree_print_code::visit_break_expression (tree_break_expression&)
 {
   indent ();
 
@@ -123,7 +123,7 @@
 }
 
 void
-tree_print_code::visit_continue_command (tree_continue_command&)
+tree_print_code::visit_continue_expression (tree_continue_expression&)
 {
   indent ();
 
@@ -782,7 +782,7 @@
 }
 
 void
-tree_print_code::visit_return_command (tree_return_command&)
+tree_print_code::visit_return_expression (tree_return_expression&)
 {
   indent ();
 
--- a/src/pt-pr-code.h	Tue Nov 12 21:14:04 2002 +0000
+++ b/src/pt-pr-code.h	Tue Nov 12 23:05:41 2002 +0000
@@ -53,11 +53,11 @@
 
   void visit_binary_expression (tree_binary_expression&);
 
-  void visit_break_command (tree_break_command&);
+  void visit_break_expression (tree_break_expression&);
 
   void visit_colon_expression (tree_colon_expression&);
 
-  void visit_continue_command (tree_continue_command&);
+  void visit_continue_expression (tree_continue_expression&);
 
   void visit_decl_command (tree_decl_command&);
 
@@ -107,7 +107,7 @@
 
   void visit_prefix_expression (tree_prefix_expression&);
 
-  void visit_return_command (tree_return_command&);
+  void visit_return_expression (tree_return_expression&);
 
   void visit_return_list (tree_return_list&);
 
--- a/src/pt-stmt.cc	Tue Nov 12 21:14:04 2002 +0000
+++ b/src/pt-stmt.cc	Tue Nov 12 23:05:41 2002 +0000
@@ -165,11 +165,11 @@
 	  if (error_state)
 	    break;
 
-	  if (tree_break_command::breaking
-	      || tree_continue_command::continuing)
+	  if (tree_break_expression::breaking
+	      || tree_continue_expression::continuing)
 	    break;
 
-	  if (tree_return_command::returning)
+	  if (tree_return_expression::returning)
 	    break;
 	}
       else
--- a/src/pt-walk.h	Tue Nov 12 21:14:04 2002 +0000
+++ b/src/pt-walk.h	Tue Nov 12 23:05:41 2002 +0000
@@ -25,9 +25,9 @@
 
 class tree_argument_list;
 class tree_binary_expression;
-class tree_break_command;
+class tree_break_expression;
 class tree_colon_expression;
-class tree_continue_command;
+class tree_continue_expression;
 class tree_decl_command;
 class tree_decl_elt;
 class tree_decl_init_list;
@@ -53,7 +53,7 @@
 class plot_range;
 class tree_postfix_expression;
 class tree_prefix_expression;
-class tree_return_command;
+class tree_return_expression;
 class tree_return_list;
 class tree_simple_assignment;
 class tree_statement;
@@ -80,13 +80,13 @@
   visit_binary_expression (tree_binary_expression&) = 0;
 
   virtual void
-  visit_break_command (tree_break_command&) = 0;
+  visit_break_expression (tree_break_expression&) = 0;
 
   virtual void
   visit_colon_expression (tree_colon_expression&) = 0;
 
   virtual void
-  visit_continue_command (tree_continue_command&) = 0;
+  visit_continue_expression (tree_continue_expression&) = 0;
 
   virtual void
   visit_decl_command (tree_decl_command&) = 0;
@@ -164,7 +164,7 @@
   visit_prefix_expression (tree_prefix_expression&) = 0;
 
   virtual void
-  visit_return_command (tree_return_command&) = 0;
+  visit_return_expression (tree_return_expression&) = 0;
 
   virtual void
   visit_return_list (tree_return_list&) = 0;
--- a/src/toplev.cc	Tue Nov 12 21:14:04 2002 +0000
+++ b/src/toplev.cc	Tue Nov 12 23:05:41 2002 +0000
@@ -140,14 +140,14 @@
 
 		  if (! (interactive || forced_interactive))
 		    {
-		      bool quit = (tree_return_command::returning
-				   || tree_break_command::breaking);
+		      bool quit = (tree_return_expression::returning
+				   || tree_break_expression::breaking);
 
-		      if (tree_return_command::returning)
-			tree_return_command::returning = 0;
+		      if (tree_return_expression::returning)
+			tree_return_expression::returning = 0;
 
-		      if (tree_break_command::breaking)
-			tree_break_command::breaking--;
+		      if (tree_break_expression::breaking)
+			tree_break_expression::breaking--;
 
 		      if (quit)
 			break;