# HG changeset patch # User jwe # Date 862372410 0 # Node ID facd9d10e5c14ac447a193564c2dc9828050556d # Parent c5b7a019b9ed55c10b84fd3eb01c871d897cedc1 [project @ 1997-04-30 03:53:07 by jwe] diff --git a/src/ov.cc b/src/ov.cc --- a/src/ov.cc +++ b/src/ov.cc @@ -42,6 +42,7 @@ #include "ov-str-mat.h" #include "ov-range.h" #include "ov-struct.h" +#include "ov-file.h" #include "ov-list.h" #include "ov-colon.h" #include "ov-va-args.h" @@ -110,37 +111,6 @@ // Allow divide by zero errors to be suppressed. bool Vwarn_divide_by_zero; -// Indentation level for structures. -int struct_indent = 0; - -// XXX FIXME XXX -void -increment_struct_indent (void) -{ - struct_indent += 2; -} - -void -decrement_struct_indent (void) -{ - struct_indent -= 2; -} - -// Indentation level for lists. -int list_indent = 0; - -void -increment_list_indent (void) -{ - list_indent += 2; -} - -void -decrement_list_indent (void) -{ - list_indent -= 2; -} - // XXX FIXME XXX // Octave's value type. @@ -176,6 +146,14 @@ retval = "\\"; break; + case lshift: + retval = "<<"; + break; + + case rshift: + retval = ">>"; + break; + case lt: retval = "<"; break; @@ -262,6 +240,14 @@ retval = "/="; break; + case lshift_eq: + retval = "<<="; + break; + + case rshift_eq: + retval = ">>="; + break; + case el_mul_eq: retval = ".*="; break; @@ -426,6 +412,12 @@ rep->count = 1; } +octave_value::octave_value (octave_stream *s, int n) + : rep (new octave_file (s, n)) +{ + rep->count = 1; +} + octave_value::octave_value (const octave_value_list& l) : rep (new octave_list (l)) { @@ -488,7 +480,7 @@ static void gripe_no_conversion (const string& tn1, const string& tn2) { - error ("no suitable conversion found for assignment of %s to indexed %s", + error ("no suitable conversion found for assignment of `%s' to indexed `%s'", tn2.c_str (), tn1.c_str ()); } @@ -535,6 +527,18 @@ return rep->map_value (); } +octave_stream * +octave_value::stream_value (void) const +{ + return rep->stream_value (); +} + +int +octave_value::stream_number (void) const +{ + return rep->stream_number (); +} + octave_value_list octave_value::list_value (void) const { @@ -630,70 +634,28 @@ } void -octave_value::print (bool pr_as_read_syntax) -{ - print (octave_stdout, pr_as_read_syntax); -} - -void -octave_value::print_with_name (const string& name, bool print_padding) -{ - print_with_name (octave_stdout, name, print_padding); -} - -void octave_value::print_with_name (ostream& output_buf, const string& name, - bool print_padding) + bool print_padding) const { - bool pad_after = false; - - if (Vprint_answer_id_name) - { - if (print_as_scalar ()) - output_buf << name << " = "; - else if (is_map ()) - { - pad_after = true; - output_buf << name << " ="; - } - else - { - pad_after = true; - output_buf << name << " =\n\n"; - } - } + bool pad_after = print_name_tag (output_buf, name); print (output_buf); if (print_padding && pad_after) - output_buf << "\n"; -} - -bool -octave_value::print_as_scalar (void) -{ - int nr = rows (); - int nc = columns (); - - return (is_scalar_type () - || (is_string () && nr <= 1) - || (is_matrix_type () - && ((nr == 1 && nc == 1) - || nr == 0 - || nc == 0))); + newline (output_buf); } static void gripe_indexed_assignment (const string& tn1, const string& tn2) { - error ("assignment of %s to indexed %s not implemented", + error ("assignment of `%s' to indexed `%s' not implemented", tn2.c_str (), tn1.c_str ()); } static void gripe_conversion_failed (const string& tn1, const string& tn2) { - error ("type conversion for assignment of %s to indexed %s failed", + error ("type conversion for assignment of `%s' to indexed `%s' failed", tn2.c_str (), tn1.c_str ()); } @@ -826,7 +788,7 @@ static void gripe_binary_op (const string& on, const string& tn1, const string& tn2) { - error ("binary operator %s not implemented for %s by %s operations", + error ("binary operator `%s' not implemented for `%s' by `%s' operations", on.c_str (), tn1.c_str (), tn2.c_str ()); } @@ -886,6 +848,52 @@ return retval; } +// Current indentation. +int octave_value::curr_print_indent_level = 0; + +// Nonzero means we are at the beginning of a line. +bool octave_value::beginning_of_line = true; + +// Each print() function should call this before printing anything. +// +// This doesn't need to be fast, but isn't there a better way? + +void +octave_value::indent (ostream& os) const +{ + assert (curr_print_indent_level >= 0); + + if (beginning_of_line) + { + // XXX FIXME XXX -- do we need this? + // os << prefix; + + for (int i = 0; i < curr_print_indent_level; i++) + os << " "; + + beginning_of_line = false; + } +} + +// All print() functions should use this to print new lines. + +void +octave_value::newline (ostream& os) const +{ + os << "\n"; + + beginning_of_line = true; +} + +// For ressetting print state. + +void +octave_value::reset (void) const +{ + beginning_of_line = true; + curr_print_indent_level = 0; +} + void install_types (void) { @@ -900,6 +908,7 @@ octave_char_matrix::register_type (); octave_char_matrix_str::register_type (); octave_struct::register_type (); + octave_file::register_type (); octave_list::register_type (); octave_all_va_args::register_type (); octave_magic_colon::register_type (); diff --git a/src/ov.h b/src/ov.h --- a/src/ov.h +++ b/src/ov.h @@ -41,6 +41,7 @@ #include "str-vec.h" class Octave_map; +class octave_stream; class octave_value_list; // Constants. @@ -83,6 +84,8 @@ div, pow, ldiv, + lshift, + rshift, lt, le, eq, @@ -107,6 +110,8 @@ sub_eq, mul_eq, div_eq, + lshift_eq, + rshift_eq, el_mul_eq, el_div_eq, el_and_eq, @@ -142,6 +147,7 @@ octave_value (double base, double limit, double inc); octave_value (const Range& r); octave_value (const Octave_map& m); + octave_value (octave_stream *s, int n); octave_value (const octave_value_list& m); octave_value (octave_value::magic_colon); octave_value (octave_value::all_va_args); @@ -355,6 +361,10 @@ virtual Octave_map map_value (void) const; + virtual octave_stream *stream_value (void) const; + + virtual int stream_number (void) const; + virtual octave_value_list list_value (void) const; virtual bool bool_value (void) const @@ -402,15 +412,17 @@ virtual void convert_to_row_or_column_vector (void) { rep->convert_to_row_or_column_vector (); } - void print (bool pr_as_read_syntax = false); - - virtual void print (ostream& os, bool pr_as_read_syntax = false) + virtual void print (ostream& os, bool pr_as_read_syntax = false) const { rep->print (os, pr_as_read_syntax); } - void print_with_name (const string& name, bool print_padding = true); + virtual void print_raw (ostream& os, bool pr_as_read_syntax = false) const + { rep->print_raw (os, pr_as_read_syntax); } + + virtual bool print_name_tag (ostream& os, const string& name) const + { return rep->print_name_tag (os, name); } void print_with_name (ostream& os, const string& name, - bool print_padding = true); + bool print_padding = true) const; virtual int type_id (void) const { return rep->type_id (); } @@ -422,14 +434,28 @@ const octave_value&, const octave_value&); - // Can we make these go away? - - bool print_as_scalar (void); - protected: octave_value (const octave_xvalue&) : rep (0) { } + void reset_indent_level (void) const + { curr_print_indent_level = 0; } + + void increment_indent_level (void) const + { curr_print_indent_level += 2; } + + void decrement_indent_level (void) const + { curr_print_indent_level -= 2; } + + int current_print_indent_level (void) const + { return curr_print_indent_level; } + + void newline (ostream& os) const; + + void indent (ostream& os) const; + + void reset (void) const; + private: static octave_allocator allocator; @@ -449,6 +475,9 @@ bool try_assignment (assign_op, const octave_value_list& idx, const octave_value& rhs); + + static int curr_print_indent_level; + static bool beginning_of_line; }; // If TRUE, allow assignments like diff --git a/src/pr-output.cc b/src/pr-output.cc --- a/src/pr-output.cc +++ b/src/pr-output.cc @@ -1064,7 +1064,6 @@ os << "[]"; if (Vprint_empty_dimensions) os << "(" << nr << "x" << nc << ")"; - os << "\n"; } } @@ -1087,9 +1086,6 @@ os << " Columns " << col + 1 << " and " << lim << ":\n"; else os << " Columns " << col + 1 << " through " << lim << ":\n"; - - if (! compact_format) - os << "\n"; } } @@ -1111,9 +1107,6 @@ else pr_float (os, d); } - - if (! pr_as_read_syntax) - os << "\n"; } void @@ -1263,9 +1256,6 @@ else pr_complex (os, c); } - - if (! pr_as_read_syntax) - os << "\n"; } void @@ -1542,7 +1532,7 @@ int nargin = args.length (); if (nargin == 1) - args(0).print (); + args(0).print (octave_stdout); else print_usage ("disp"); diff --git a/src/symtab.cc b/src/symtab.cc --- a/src/symtab.cc +++ b/src/symtab.cc @@ -36,7 +36,6 @@ #include "error.h" #include "oct-sym.h" #include "oct-fcn.h" -#include "pt-const.h" #include "symtab.h" #include "utils.h" #include "variables.h"