changeset 2900:5ed088015839

[project @ 1997-04-30 03:26:56 by jwe]
author jwe
date Wed, 30 Apr 1997 03:37:00 +0000
parents 0d79a8c11a2b
children e6d25bc478dd
files src/help.cc src/input.cc src/lex.l src/pt-const.cc src/pt-exp-base.h src/pt-exp.cc src/pt-exp.h src/pt-id.cc src/pt-indir.cc src/pt-mvr.cc src/pt-pr-code.cc src/variables.cc
diffstat 12 files changed, 80 insertions(+), 76 deletions(-) [+]
line wrap: on
line diff
--- a/src/help.cc
+++ b/src/help.cc
@@ -54,8 +54,6 @@
 #include "oct-obj.h"
 #include "pager.h"
 #include "pathsearch.h"
-#include "pt-const.h"
-#include "pt-exp.h"
 #include "pt-pr-code.h"
 #include "sighandlers.h"
 #include "symtab.h"
@@ -834,16 +832,14 @@
 
 		  assert (defn && defn->is_constant ());
 
-		  tree_constant *tmp = static_cast<tree_constant *> (defn);
-
 		  int var_ok = 1;
 
 		  // XXX FIXME XXX -- need to handle structure
 		  // references correctly.
 
-		  if (tmp)
+		  if (defn)
 		    {
-		      octave_value vtmp = tmp->value ();
+		      octave_value vtmp = defn->eval ();
 
 		      if (vtmp.is_map ())
 			error ("type: operations on structs not implemented");
@@ -876,7 +872,7 @@
 		      tree_print_code tpc (output_buf, "", pr_orig_txt);
 
 		      // XXX FIXME XXX
-		      // tmp->accept (tpc);
+		      // defn->accept (tpc);
 
 		      if (nargout == 0)
 			output_buf << "\n";
--- a/src/input.cc
+++ b/src/input.cc
@@ -1102,11 +1102,13 @@
       else
 	{
 	  int parse_status = 0;
+
 	  retval = eval_string (input_buf, true, parse_status);
+
 	  if (retval.is_defined ())
 	    {
 	      if (debug)
-		retval.print ();
+		retval.print (octave_stdout);
 	    }
 	  else
 	    retval = Matrix ();
--- a/src/lex.l
+++ b/src/lex.l
@@ -586,6 +586,8 @@
 "="	{ BIN_OP_RETURN ('=', true); }
 "&&"	{ BIN_OP_RETURN (EXPR_AND_AND, false); }
 "||"	{ BIN_OP_RETURN (EXPR_OR_OR, false); }
+"<<"	{ BIN_OP_RETURN (LSHIFT, false); }
+">>"	{ BIN_OP_RETURN (RSHIFT, false); }
 
 {NOT} {
     if (lexer_flags.plotting && ! lexer_flags.in_plot_range)
@@ -638,6 +640,8 @@
 "./="	{ BIN_OP_RETURN (EDIV_EQ, false); }
 "&="	{ BIN_OP_RETURN (AND_EQ, false); }
 "|="	{ BIN_OP_RETURN (OR_EQ, false); }
+"<<="	{ BIN_OP_RETURN (LSHIFT_EQ, false); }
+">>="	{ BIN_OP_RETURN (RSHIFT_EQ, false); }
 
 %{
 // Unrecognized input is a lexical error.
--- a/src/pt-const.cc
+++ b/src/pt-const.cc
@@ -31,6 +31,7 @@
 #include <iostream.h>
 
 #include "oct-obj.h"
+#include "pager.h"
 #include "pt-const.h"
 #include "pt-walk.h"
 
@@ -52,7 +53,7 @@
 tree_constant::eval (bool print_result)
 {
   if (print_result)
-    val.print ();
+    val.print (octave_stdout);
 
   return val;
 }
--- a/src/pt-exp-base.h
+++ b/src/pt-exp-base.h
@@ -89,7 +89,7 @@
 
   virtual octave_value eval (bool print = false) = 0;
 
-  virtual const char *oper (void) const { return "<unknown>"; }
+  virtual string oper (void) const { return "<unknown>"; }
 
   virtual string original_text (void) const;
 
--- a/src/pt-exp.cc
+++ b/src/pt-exp.cc
@@ -104,25 +104,26 @@
   return retval;
 }
 
-const char *
+string
 tree_prefix_expression::oper (void) const
 {
-  static const char *op;
+  string retval = "<unknown>";
+
   switch (etype)
     {
     case increment:
-      op = "++";
+      retval = "++";
       break;
 
     case decrement:
-      op = "--";
+      retval = "--";
       break;
 
     default:
-      op = "<unknown>";
       break;
     }
-  return op;
+
+  return retval;
 }
 
 void
@@ -130,7 +131,7 @@
 {
   if (error_state > 0)
     ::error ("evaluating prefix operator `%s' near line %d, column %d",
-	     oper (), line (), column ());
+	     oper () . c_str (), line (), column ());
 }
 
 void
@@ -183,25 +184,26 @@
   return retval;
 }
 
-const char *
+string
 tree_postfix_expression::oper (void) const
 {
-  static const char *op;
+  string retval = "<unknown>";
+
   switch (etype)
     {
     case increment:
-      op = "++";
+      retval = "++";
       break;
 
     case decrement:
-      op = "--";
+      retval = "--";
       break;
 
     default:
-      op = "<unknown>";
       break;
     }
-  return op;
+
+  return retval;
 }
 
 void
@@ -209,7 +211,7 @@
 {
   if (error_state > 0)
     ::error ("evaluating postfix operator `%s' near line %d, column %d",
-	     oper (), line (), column ());
+	     oper () . c_str (), line (), column ());
 }
 
 void
@@ -270,33 +272,34 @@
   return retval;
 }
 
-const char *
+string
 tree_unary_expression::oper (void) const
 {
-  static const char *op;
+  string retval = "<unknown>";
+
   switch (etype)
     {
     case unot:
-      op = "!";
+      retval = "!";
       break;
 
     case uminus:
-      op = "-";
+      retval = "-";
       break;
 
     case transpose:
-      op = ".'";
+      retval = ".'";
       break;
 
     case hermitian:
-      op = "'";
+      retval = "'";
       break;
 
     default:
-      op = "<unknown>";
       break;
     }
-  return op;
+
+  return retval;
 }
 
 void
@@ -304,7 +307,7 @@
 {
   if (error_state > 0)
     ::error ("evaluating unary operator `%s' near line %d, column %d",
-	     oper (), line (), column ());
+	     oper () . c_str (), line (), column ());
 }
 
 void
@@ -357,11 +360,10 @@
   return retval;
 }
 
-const char *
+string
 tree_binary_expression::oper (void) const
 {
-  // XXX FIXME XXX
-  return octave_value::binary_op_as_string (etype) . c_str ();
+  return octave_value::binary_op_as_string (etype);
 }
 
 void
@@ -369,7 +371,7 @@
 {
   if (error_state > 0)
     ::error ("evaluating binary operator `%s' near line %d, column %d",
-	     oper (), line (), column ());
+	     oper () . c_str (), line (), column ());
 }
 
 void
@@ -448,25 +450,26 @@
   return retval;
 }
 
-const char *
+string
 tree_boolean_expression::oper (void) const
 {
-  static const char *op;
+  string retval = "<unknown>";
+
   switch (etype)
     {
     case bool_and:
-      op = "&&";
+      retval = "&&";
       break;
 
     case bool_or:
-      op = "||";
+      retval = "||";
       break;
 
     default:
-      op = "<unknown>";
       break;
     }
-  return op;
+
+  return retval;
 }
 
 // Simple assignment expressions.
@@ -590,7 +593,7 @@
   // undefined) print b = [ 0; 2 ], which is more Matlab-like.
 
   if (! error_state && print && lhs_val.is_defined ())
-    lhs_val.print_with_name (lhs->name ());
+    lhs_val.print_with_name (octave_stdout, lhs->name ());
 
   return retval;
 }
@@ -609,10 +612,10 @@
     }
 }
 
-const char *
+string
 tree_simple_assignment_expression::oper (void) const
 {
-  return octave_value::assign_op_as_string (etype) . c_str ();
+  return octave_value::assign_op_as_string (etype);
 }
 
 void
--- a/src/pt-exp.h
+++ b/src/pt-exp.h
@@ -72,7 +72,7 @@
   bool is_prefix_expression (void) const
     { return true; }
 
-  const char *oper (void) const;
+  string oper (void) const;
 
   tree_identifier *ident (void) { return id; }
 
@@ -114,7 +114,7 @@
 
   void eval_error (void);
 
-  const char *oper (void) const;
+  string oper (void) const;
 
   tree_identifier *ident (void) { return id; }
 
@@ -159,7 +159,7 @@
 
   void eval_error (void);
 
-  const char *oper (void) const;
+  string oper (void) const;
 
   bool is_prefix_op (void) { return (etype == unot || etype == uminus); }
 
@@ -204,7 +204,7 @@
 
   void eval_error (void);
 
-  const char *oper (void) const;
+  string oper (void) const;
 
   tree_expression *lhs (void) { return op_lhs; }
   tree_expression *rhs (void) { return op_rhs; }
@@ -248,7 +248,7 @@
 
   octave_value eval (bool print = false);
 
-  const char *oper (void) const;
+  string oper (void) const;
 
 private:
 
@@ -302,7 +302,7 @@
 
   void eval_error (void);
 
-  const char *oper (void) const;
+  string oper (void) const;
 
   tree_indirect_ref *left_hand_side (void) { return lhs; }
 
--- a/src/pt-id.cc
+++ b/src/pt-id.cc
@@ -32,10 +32,11 @@
 #include "oct-obj.h"
 #include "oct-fcn.h"
 #include "oct-sym.h"
-#include "symtab.h"
+#include "pager.h"
 #include "pt-const.h"
 #include "pt-id.h"
 #include "pt-walk.h"
+#include "symtab.h"
 #include "utils.h"
 
 // Symbols from the symbol table.
@@ -290,7 +291,7 @@
 	  if (maybe_do_ans_assign && ! object_to_eval->is_constant ())
 	    bind_ans (retval, print);
 	  else if (print)
-	    retval.print_with_name (name ());
+	    retval.print_with_name (octave_stdout, name ());
 	}
       else if (object_to_eval && object_to_eval->is_constant ())
 	eval_undefined_error ();
--- a/src/pt-indir.cc
+++ b/src/pt-indir.cc
@@ -34,11 +34,11 @@
 #include "oct-obj.h"
 #include "oct-sym.h"
 #include "pager.h"
-#include "symtab.h"
 #include "pt-const.h"
 #include "pt-id.h"
 #include "pt-indir.h"
 #include "pt-walk.h"
+#include "symtab.h"
 #include "utils.h"
 
 // Indirect references to values (structure elements).
@@ -100,7 +100,7 @@
 	  if (maybe_do_ans_assign)
 	    bind_ans (retval, print);
 	  else if (print)
-	    retval.print_with_name (name ());
+	    retval.print_with_name (octave_stdout, name ());
 	}
     }
 
--- a/src/pt-mvr.cc
+++ b/src/pt-mvr.cc
@@ -335,7 +335,8 @@
 		octave_stdout << "\n";
 
 	      if (print)
-		results(i).print_with_name (lhs_expr->name (), 0);
+		results(i).print_with_name (octave_stdout,
+					    lhs_expr->name (), 0);
 
 	      pad_after = true;
 
--- a/src/pt-pr-code.cc
+++ b/src/pt-pr-code.cc
@@ -1161,7 +1161,11 @@
  
   if (beginning_of_line)
     {
-      os.form ("%s%*s", prefix.c_str (), curr_print_indent_level, "");
+      os << prefix;
+
+      for (int i = 0; i < curr_print_indent_level; i++)
+	os << " ";
+
       beginning_of_line = false;
     }
 }
--- a/src/variables.cc
+++ b/src/variables.cc
@@ -74,9 +74,7 @@
 #include "oct-builtin.h"
 #include "oct-mapper.h"
 #include "oct-usr-fcn.h"
-#include "pt-const.h"
 #include "oct-obj.h"
-#include "pt-exp.h"
 #include "pt-id.h"
 #include "pt-indir.h"
 #include "pt-mat.h"
@@ -1007,14 +1005,14 @@
 
   if (sr->is_variable ())
     {
-      // Would be nice not to have this cast.  XXX FIXME XXX
+      octave_symbol *tmp = sr->def ();
 
-      tree_constant *tmp = (tree_constant *) sr->def ();
+      octave_value vtmp;
+
       if (tmp)
-	tmp = new tree_constant (*tmp);
-      else
-	tmp = new tree_constant ();
-      gsr->define (tmp);
+	vtmp = tmp->eval ();
+
+      gsr->define (vtmp);
     }
   else
     sr->clear ();
@@ -1023,7 +1021,7 @@
   // to hide it with a variable.
 
   if (gsr->is_function ())
-    gsr->define ((tree_constant *) 0);
+    gsr->define (octave_value ());
 
   sr->alias (gsr, 1);
   sr->mark_as_linked_to_global ();
@@ -1498,16 +1496,10 @@
 {
   static symbol_record *sr = global_sym_tab->lookup ("ans", true);
 
-  tree_identifier *ans_id = new tree_identifier (sr);
-  tree_constant *tmp = new tree_constant (val);
+  sr->define (val);
 
-  // XXX FIXME XXX -- making ans_id static, passing its address to
-  // tree_simple_assignment_expression along with a flag to not delete
-  // it seems to create a memory leak.  Hmm.
-
-  tree_simple_assignment_expression tmp_ass (ans_id, tmp, false, true);
-
-  tmp_ass.eval (print);
+  if (print)
+    val.print_with_name (octave_stdout, "ans");
 }
 
 void