# HG changeset patch # User jwe # Date 823270210 0 # Node ID effa9400766fe5aab4a39ccceb29ee2f5c7f8666 # Parent b14829582cc44e7e088b14b1b858c140678ee857 [project @ 1996-02-02 14:07:51 by jwe] diff --git a/src/pt-base.cc b/src/pt-base.cc --- a/src/pt-base.cc +++ b/src/pt-base.cc @@ -1,7 +1,7 @@ // pt-base.cc -*- C++ -*- /* -Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton +Copyright (C) 1996 John W. Eaton This file is part of Octave. @@ -40,7 +40,7 @@ int tree_print_code::curr_print_indent_level = 0; // Nonzero means we are at the beginning of a line. -int tree_print_code::beginning_of_line = 1; +bool tree_print_code::beginning_of_line = true; // All print_code() functions should use this to print new lines. @@ -49,7 +49,7 @@ { os << "\n"; - beginning_of_line = 1; + beginning_of_line = true; } // Each print_code() function should call this before printing @@ -65,7 +65,7 @@ if (beginning_of_line) { os.form ("%s%*s", user_pref.ps4.c_str (), curr_print_indent_level, ""); - beginning_of_line = 0; + beginning_of_line = false; } } @@ -74,7 +74,7 @@ void tree_print_code::print_code_reset (void) { - beginning_of_line = 1; + beginning_of_line = true; curr_print_indent_level = 0; } diff --git a/src/pt-base.h b/src/pt-base.h --- a/src/pt-base.h +++ b/src/pt-base.h @@ -1,7 +1,7 @@ // pt-base.h -*- C++ -*- /* -Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton +Copyright (C) 1996 John W. Eaton This file is part of Octave. @@ -57,7 +57,7 @@ private: static int curr_print_indent_level; - static int beginning_of_line; + static bool beginning_of_line; }; // Base class for the parse tree. diff --git a/src/pt-cmd.cc b/src/pt-cmd.cc --- a/src/pt-cmd.cc +++ b/src/pt-cmd.cc @@ -1,7 +1,7 @@ // pt-cmd.cc -*- C++ -*- /* -Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton +Copyright (C) 1996 John W. Eaton This file is part of Octave. @@ -56,7 +56,7 @@ #include "variables.h" // Decide if it's time to quit a for or while loop. -static inline int +static inline bool quit_loop_now (void) { // Maybe handle `continue N' someday... @@ -64,7 +64,7 @@ if (continuing) continuing--; - int quit = (returning || breaking || continuing); + bool quit = (returning || breaking || continuing); if (breaking) breaking--; @@ -212,13 +212,13 @@ inline void tree_for_command::do_for_loop_once (tree_return_list *lst, - const Octave_object& rhs, int& quit) + const Octave_object& rhs, bool& quit) { - quit = 0; + quit = false; tree_oct_obj *tmp = new tree_oct_obj (rhs); tree_multi_assignment_expression tmp_ass (lst, tmp, 1); - tmp_ass.eval (0); + tmp_ass.eval (false); if (error_state) { @@ -232,7 +232,7 @@ if (error_state) { eval_error (); - quit = 1; + quit = true; return; } } @@ -242,13 +242,13 @@ inline void tree_for_command::do_for_loop_once (tree_index_expression *idx_expr, - const tree_constant& rhs, int& quit) + const tree_constant& rhs, bool& quit) { - quit = 0; + quit = false; tree_constant *tmp = new tree_constant (rhs); - tree_simple_assignment_expression tmp_ass (idx_expr, tmp, 1); - tmp_ass.eval (0); + tree_simple_assignment_expression tmp_ass (idx_expr, tmp, true); + tmp_ass.eval (false); if (error_state) { @@ -262,7 +262,7 @@ if (error_state) { eval_error (); - quit = 1; + quit = true; return; } } @@ -272,9 +272,9 @@ inline void tree_for_command::do_for_loop_once (tree_identifier *ident, - tree_constant& rhs, int& quit) + tree_constant& rhs, bool& quit) { - quit = 0; + quit = false; ident->assign (rhs); @@ -290,7 +290,7 @@ if (error_state) { eval_error (); - quit = 1; + quit = true; return; } } @@ -305,7 +305,7 @@ for (int i = 0; i < steps; i++) \ { \ tree_constant rhs (val); \ - int quit = 0; \ + bool quit = false; \ do_for_loop_once (ident, rhs, quit); \ if (quit) \ break; \ @@ -314,7 +314,7 @@ for (int i = 0; i < steps; i++) \ { \ Octave_object rhs (val); \ - int quit = 0; \ + bool quit = false; \ do_for_loop_once (id_list, rhs, quit); \ if (quit) \ break; \ @@ -323,7 +323,7 @@ for (int i = 0; i < steps; i++) \ { \ tree_constant rhs (val); \ - int quit = 0; \ + bool quit = false; \ do_for_loop_once (tmp_id, rhs, quit); \ if (quit) \ break; \ @@ -337,7 +337,7 @@ if (error_state || ! expr) return; - tree_constant tmp_expr = expr->eval (0); + tree_constant tmp_expr = expr->eval (false); if (error_state || tmp_expr.is_undefined ()) { @@ -365,7 +365,7 @@ if (tmp_expr.is_scalar_type ()) { - int quit = 0; + bool quit = false; if (ident) do_for_loop_once (ident, tmp_expr, quit); else if (id_list) @@ -430,7 +430,7 @@ tree_constant rhs (tmp_val); - int quit = 0; + bool quit = false; do_for_loop_once (ident, rhs, quit); if (quit) @@ -445,7 +445,7 @@ Octave_object rhs (tmp_val); - int quit = 0; + bool quit = false; do_for_loop_once (id_list, rhs, quit); if (quit) @@ -460,7 +460,7 @@ tree_constant rhs (tmp_val); - int quit = 0; + bool quit = false; do_for_loop_once (tmp_id, rhs, quit); if (quit) @@ -478,7 +478,7 @@ { tree_constant rhs (tmp_val.contents (p)); - int quit; + bool quit = false; do_for_loop_once (ident, rhs, quit); if (quit) @@ -499,7 +499,7 @@ tmp (1) = tmp_val.key (p); tmp (0) = tmp_val.contents (p); - int quit; + bool quit = false; do_for_loop_once (id_list, tmp, quit); if (quit) @@ -514,7 +514,7 @@ { tree_constant rhs = tmp_val.contents (p); - int quit; + bool quit = false; do_for_loop_once (tmp_id, rhs, quit); if (quit) @@ -631,7 +631,7 @@ breaking = 0; if (list) - list->eval (1); + list->eval (true); // This is the one for breaking. (The unwind_protects are popped // off the stack in the reverse of the order they are pushed on). @@ -668,7 +668,7 @@ } if (try_code) - try_code->eval (1); + try_code->eval (true); if (catch_code && error_state) { @@ -749,7 +749,7 @@ breaking = 0; if (list) - list->eval (1); + list->eval (true); // This is the one for breaking. (The unwind_protects are popped // off the stack in the reverse of the order they are pushed on). @@ -785,7 +785,7 @@ add_unwind_protect (do_unwind_protect_cleanup_code, cleanup_code); if (unwind_protect_code) - unwind_protect_code->eval (1); + unwind_protect_code->eval (true); run_unwind_protect (); } diff --git a/src/pt-cmd.h b/src/pt-cmd.h --- a/src/pt-cmd.h +++ b/src/pt-cmd.h @@ -1,7 +1,7 @@ // pt-cmd.h -*- C++ -*- /* -Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton +Copyright (C) 1996 John W. Eaton This file is part of Octave. @@ -146,13 +146,13 @@ private: void do_for_loop_once (tree_return_list *lst, - const Octave_object& rhs, int& quit); + const Octave_object& rhs, bool& quit); void do_for_loop_once (tree_index_expression *idx_expr, - const tree_constant& rhs, int& quit); + const tree_constant& rhs, bool& quit); void do_for_loop_once (tree_identifier *ident, - tree_constant& rhs, int& quit); + tree_constant& rhs, bool& quit); tree_index_expression *id; // Identifier to modify. tree_return_list *id_list; // List of identifiers to modify. diff --git a/src/pt-const.cc b/src/pt-const.cc --- a/src/pt-const.cc +++ b/src/pt-const.cc @@ -1,7 +1,7 @@ // pt-const.cc -*- C++ -*- /* -Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton +Copyright (C) 1996 John W. Eaton This file is part of Octave. @@ -100,16 +100,18 @@ structure_indent_level -= 2; } -static int +static bool any_element_is_complex (const ComplexMatrix& a) { int nr = a.rows (); int nc = a.columns (); + for (int j = 0; j < nc; j++) for (int i = 0; i < nr; i++) if (imag (a.elem (i, j)) != 0.0) - return 1; - return 0; + return true; + + return false; } // The following three variables could be made static members of the @@ -188,8 +190,8 @@ } tree_constant -tree_constant::lookup_map_element (const string& ref, int insert, - int silent) +tree_constant::lookup_map_element (const string& ref, bool insert, + bool silent) { tree_constant retval; @@ -218,8 +220,8 @@ } tree_constant -tree_constant::lookup_map_element (SLList& list, int insert, - int silent) +tree_constant::lookup_map_element (SLList& list, bool insert, + bool silent) { tree_constant retval; @@ -258,7 +260,7 @@ } void -tree_constant::print_with_name (const string& name, int print_padding) +tree_constant::print_with_name (const string& name, bool print_padding) { ostrstream output_buf; print_with_name (output_buf, name, print_padding); @@ -268,9 +270,9 @@ void tree_constant::print_with_name (ostream& output_buf, const string& name, - int print_padding) + bool print_padding) { - int pad_after = 0; + bool pad_after = false; if (user_pref.print_answer_id_name) { @@ -278,7 +280,7 @@ output_buf << name << " = "; else { - pad_after = 1; + pad_after = true; output_buf << name << " =\n\n"; } } @@ -392,7 +394,7 @@ } Octave_object -tree_constant::eval (int print, int, const Octave_object& args) +tree_constant::eval (bool print, int, const Octave_object& args) { Octave_object retval; @@ -705,7 +707,7 @@ type_tag = char_matrix_constant_str; } -TC_REP::tree_constant_rep (const charMatrix& chm, int is_str) +TC_REP::tree_constant_rep (const charMatrix& chm, bool is_str) { char_matrix = new charMatrix (chm); type_tag = is_str ? char_matrix_constant_str : char_matrix_constant; @@ -1058,7 +1060,7 @@ return retval; } -int +bool TC_REP::valid_as_scalar_index (void) const { return (type_tag == magic_colon @@ -1071,7 +1073,7 @@ && NINT (range->base ()) == 1)); } -int +bool TC_REP::valid_as_zero_index (void) const { return ((type_tag == scalar_constant @@ -1086,10 +1088,10 @@ && NINT (range->base ()) == 0)); } -int +bool TC_REP::is_true (void) const { - int retval = 0; + int retval = false; if (error_state) return retval; @@ -1147,7 +1149,7 @@ } double -TC_REP::double_value (int force_str_conv) const +TC_REP::double_value (bool force_string_conv) const { double retval = octave_NaN; @@ -1207,7 +1209,7 @@ case char_matrix_constant_str: { - int flag = force_str_conv; + int flag = force_string_conv; if (! flag) flag = user_pref.implicit_str_to_num_ok; @@ -1243,7 +1245,7 @@ } Matrix -TC_REP::matrix_value (int force_str_conv) const +TC_REP::matrix_value (bool force_string_conv) const { Matrix retval; @@ -1284,7 +1286,7 @@ case char_matrix_constant_str: { - int flag = force_str_conv; + int flag = force_string_conv; if (! flag) flag = user_pref.implicit_str_to_num_ok; @@ -1311,7 +1313,7 @@ } Complex -TC_REP::complex_value (int force_str_conv) const +TC_REP::complex_value (bool force_string_conv) const { Complex retval (octave_NaN, octave_NaN); @@ -1353,7 +1355,7 @@ case char_matrix_constant_str: { - int flag = force_str_conv; + int flag = force_string_conv; if (! flag) flag = user_pref.implicit_str_to_num_ok; @@ -1389,7 +1391,7 @@ } ComplexMatrix -TC_REP::complex_matrix_value (int force_str_conv) const +TC_REP::complex_matrix_value (bool force_string_conv) const { ComplexMatrix retval; @@ -1417,7 +1419,7 @@ case char_matrix_constant_str: { - int flag = force_str_conv; + int flag = force_string_conv; if (! flag) flag = user_pref.implicit_str_to_num_ok; @@ -1446,11 +1448,11 @@ // XXX FIXME XXX -- this needs to try to do some conversions... charMatrix -TC_REP::char_matrix_value (int force_str_conv) const +TC_REP::char_matrix_value (bool force_string_conv) const { charMatrix retval; - int flag = force_str_conv; + int flag = force_string_conv; if (! flag) flag = user_pref.implicit_str_to_num_ok; @@ -1510,7 +1512,7 @@ } tree_constant& -TC_REP::lookup_map_element (const string& name, int insert, int silent) +TC_REP::lookup_map_element (const string& name, bool insert, bool silent) { static tree_constant retval; @@ -1535,12 +1537,12 @@ // than relying on matrix_value() to do any possible type conversions. ColumnVector -TC_REP::vector_value (int force_str_conv, - int force_vector_conversion) const +TC_REP::vector_value (bool force_string_conv, + bool force_vector_conversion) const { ColumnVector retval; - Matrix m = matrix_value (force_str_conv); + Matrix m = matrix_value (force_string_conv); if (error_state) return retval; @@ -1579,12 +1581,12 @@ // conversions. ComplexColumnVector -TC_REP::complex_vector_value (int force_str_conv, - int force_vector_conversion) const +TC_REP::complex_vector_value (bool force_string_conv, + bool force_vector_conversion) const { ComplexColumnVector retval; - ComplexMatrix m = complex_matrix_value (force_str_conv); + ComplexMatrix m = complex_matrix_value (force_string_conv); if (error_state) return retval; @@ -1808,7 +1810,7 @@ } void -TC_REP::convert_to_matrix_type (int make_complex) +TC_REP::convert_to_matrix_type (bool make_complex) { switch (type_tag) { @@ -1877,7 +1879,7 @@ } void -TC_REP::force_numeric (int force_str_conv) +TC_REP::force_numeric (bool force_string_conv) { switch (type_tag) { @@ -1890,7 +1892,7 @@ case char_matrix_constant_str: { - if (! force_str_conv && ! user_pref.implicit_str_to_num_ok) + if (! force_string_conv && ! user_pref.implicit_str_to_num_ok) { ::error ("string to numeric conversion failed --\ default conversion turned off"); @@ -1964,7 +1966,7 @@ } tree_constant -TC_REP::make_numeric (int force_str_conv) const +TC_REP::make_numeric (bool force_string_conv) const { tree_constant retval; @@ -1992,7 +1994,7 @@ case char_matrix_constant_str: { - int flag = force_str_conv; + int flag = force_string_conv; if (! flag) flag = user_pref.implicit_str_to_num_ok; @@ -2002,7 +2004,7 @@ if (flag) { retval = *char_matrix; - retval.force_numeric (force_str_conv); + retval.force_numeric (force_string_conv); } else gripe_invalid_conversion ("string", "char matrix"); @@ -2011,7 +2013,7 @@ case range_constant: retval = *range; - retval.force_numeric (force_str_conv); + retval.force_numeric (force_string_conv); break; default: @@ -2405,8 +2407,8 @@ { tree_constant retval; - int first_empty = (a.rows () == 0 || a.columns () == 0); - int second_empty = (b.rows () == 0 || b.columns () == 0); + bool first_empty = (a.rows () == 0 || a.columns () == 0); + bool second_empty = (b.rows () == 0 || b.columns () == 0); if (first_empty || second_empty) { @@ -2795,7 +2797,7 @@ } void -TC_REP::set_index (const Octave_object& args, int rhs_is_complex) +TC_REP::set_index (const Octave_object& args, bool rhs_is_complex) { switch (type_tag) { @@ -2839,16 +2841,16 @@ } } -static inline int +static inline bool valid_scalar_indices (const Octave_object& args) { int nargin = args.length (); for (int i = 0; i < nargin; i++) if (! args(i).valid_as_scalar_index ()) - return 0; - - return 1; + return false; + + return true; } tree_constant @@ -2859,7 +2861,7 @@ if (error_state) return retval; - int originally_scalar_type = is_scalar_type (); + bool originally_scalar_type = is_scalar_type (); if (originally_scalar_type && valid_scalar_indices (args)) { @@ -3113,11 +3115,12 @@ maybe_mutate (); } -int +bool TC_REP::print_as_scalar (void) { int nr = rows (); int nc = columns (); + return (is_scalar_type () || (is_string () && nr <= 1) || (is_matrix_type () @@ -3126,7 +3129,7 @@ || nc == 0))); } -int +bool TC_REP::print_as_structure (void) { return is_map (); diff --git a/src/pt-const.h b/src/pt-const.h --- a/src/pt-const.h +++ b/src/pt-const.h @@ -1,7 +1,7 @@ // pt-const.h -*- C++ -*- /* -Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton +Copyright (C) 1996 John W. Eaton This file is part of Octave. @@ -54,269 +54,269 @@ class tree_constant_rep - { - private: - - friend class tree_constant; + { + public: - enum constant_type - { - unknown_constant, - scalar_constant, - matrix_constant, - complex_scalar_constant, - complex_matrix_constant, - char_matrix_constant, - char_matrix_constant_str, - range_constant, - map_constant, - magic_colon, - all_va_args, - }; + enum constant_type + { + unknown_constant, + scalar_constant, + matrix_constant, + complex_scalar_constant, + complex_matrix_constant, + char_matrix_constant, + char_matrix_constant_str, + range_constant, + map_constant, + magic_colon, + all_va_args, + }; - enum force_orient - { - no_orient, - row_orient, - column_orient, - }; + enum force_orient + { + no_orient, + row_orient, + column_orient, + }; - tree_constant_rep (void); + tree_constant_rep (void); - tree_constant_rep (double d); - tree_constant_rep (const Matrix& m); - tree_constant_rep (const DiagMatrix& d); - tree_constant_rep (const RowVector& v, int pcv); - tree_constant_rep (const ColumnVector& v, int pcv); + tree_constant_rep (double d); + tree_constant_rep (const Matrix& m); + tree_constant_rep (const DiagMatrix& d); + tree_constant_rep (const RowVector& v, int pcv); + tree_constant_rep (const ColumnVector& v, int pcv); - tree_constant_rep (const Complex& c); - tree_constant_rep (const ComplexMatrix& m); - tree_constant_rep (const ComplexDiagMatrix& d); - tree_constant_rep (const ComplexRowVector& v, int pcv); - tree_constant_rep (const ComplexColumnVector& v, int pcv); + tree_constant_rep (const Complex& c); + tree_constant_rep (const ComplexMatrix& m); + tree_constant_rep (const ComplexDiagMatrix& d); + tree_constant_rep (const ComplexRowVector& v, int pcv); + tree_constant_rep (const ComplexColumnVector& v, int pcv); - tree_constant_rep (const char *s); - tree_constant_rep (const string& s); - tree_constant_rep (const string_vector& s); - tree_constant_rep (const charMatrix& chm, int is_string); + tree_constant_rep (const char *s); + tree_constant_rep (const string& s); + tree_constant_rep (const string_vector& s); + tree_constant_rep (const charMatrix& chm, bool is_string); - tree_constant_rep (double base, double limit, double inc); - tree_constant_rep (const Range& r); + tree_constant_rep (double base, double limit, double inc); + tree_constant_rep (const Range& r); - tree_constant_rep (const Octave_map& m); + tree_constant_rep (const Octave_map& m); - tree_constant_rep (tree_constant_rep::constant_type t); + tree_constant_rep (tree_constant_rep::constant_type t); + + tree_constant_rep (const tree_constant_rep& t); - tree_constant_rep (const tree_constant_rep& t); + ~tree_constant_rep (void); - ~tree_constant_rep (void); + void *operator new (size_t size); + void operator delete (void *p, size_t size); - void *operator new (size_t size); - void operator delete (void *p, size_t size); + int rows (void) const; + int columns (void) const; - int rows (void) const; - int columns (void) const; + bool is_defined (void) const + { return type_tag != unknown_constant; } - int is_defined (void) const - { return type_tag != unknown_constant; } + bool is_undefined (void) const + { return type_tag == unknown_constant; } - int is_undefined (void) const - { return type_tag == unknown_constant; } + bool is_unknown (void) const + { return type_tag == unknown_constant; } - int is_unknown (void) const - { return type_tag == unknown_constant; } + bool is_real_scalar (void) const + { return type_tag == scalar_constant; } - int is_real_scalar (void) const - { return type_tag == scalar_constant; } + bool is_real_matrix (void) const + { return type_tag == matrix_constant; } - int is_real_matrix (void) const - { return type_tag == matrix_constant; } + bool is_complex_scalar (void) const + { return type_tag == complex_scalar_constant; } - int is_complex_scalar (void) const - { return type_tag == complex_scalar_constant; } + bool is_complex_matrix (void) const + { return type_tag == complex_matrix_constant; } - int is_complex_matrix (void) const - { return type_tag == complex_matrix_constant; } + bool is_char_matrix (void) const + { return type_tag == char_matrix_constant; } + + bool is_string (void) const + { return type_tag == char_matrix_constant_str; } - int is_char_matrix (void) const - { return type_tag == char_matrix_constant; } + bool is_range (void) const + { return type_tag == range_constant; } - int is_string (void) const - { return type_tag == char_matrix_constant_str; } + bool is_map (void) const + { return type_tag == map_constant; } - int is_range (void) const - { return type_tag == range_constant; } + bool is_magic_colon (void) const + { return type_tag == magic_colon; } - int is_map (void) const - { return type_tag == map_constant; } + bool is_all_va_args (void) const + { return type_tag == all_va_args; } - int is_magic_colon (void) const - { return type_tag == magic_colon; } + tree_constant all (void) const; + tree_constant any (void) const; - int is_all_va_args (void) const - { return type_tag == all_va_args; } - - tree_constant all (void) const; - tree_constant any (void) const; + bool is_real_type (void) const + { + return (type_tag == scalar_constant + || type_tag == matrix_constant + || type_tag == range_constant + || type_tag == char_matrix_constant + || type_tag == char_matrix_constant_str); + } - int is_real_type (void) const - { - return (type_tag == scalar_constant - || type_tag == matrix_constant - || type_tag == range_constant - || type_tag == char_matrix_constant - || type_tag == char_matrix_constant_str); - } + bool is_complex_type (void) const + { + return (type_tag == complex_matrix_constant + || type_tag == complex_scalar_constant); + } + + // Would be nice to get rid of the next four functions: - int is_complex_type (void) const - { - return (type_tag == complex_matrix_constant - || type_tag == complex_scalar_constant); - } + bool is_scalar_type (void) const + { + return (type_tag == scalar_constant + || type_tag == complex_scalar_constant); + } - // Would be nice to get rid of the next four functions: - - int is_scalar_type (void) const - { - return (type_tag == scalar_constant - || type_tag == complex_scalar_constant); - } + bool is_matrix_type (void) const + { + return (type_tag == matrix_constant + || type_tag == complex_matrix_constant); + } - int is_matrix_type (void) const - { - return (type_tag == matrix_constant - || type_tag == complex_matrix_constant); - } + bool is_numeric_type (void) const + { + return (type_tag == scalar_constant + || type_tag == matrix_constant + || type_tag == complex_matrix_constant + || type_tag == complex_scalar_constant); + } - int is_numeric_type (void) const - { - return (type_tag == scalar_constant - || type_tag == matrix_constant - || type_tag == complex_matrix_constant - || type_tag == complex_scalar_constant); - } + bool valid_as_scalar_index (void) const; + bool valid_as_zero_index (void) const; + + bool is_true (void) const; - int valid_as_scalar_index (void) const; - int valid_as_zero_index (void) const; - - int is_true (void) const; + bool is_empty (void) const + { + return ((! (is_magic_colon () + || is_all_va_args () + || is_unknown ())) + && (rows () == 0 + || columns () == 0)); + } - int is_empty (void) const - { - return ((! (is_magic_colon () - || is_all_va_args () - || is_unknown ())) - && (rows () == 0 - || columns () == 0)); - } + double double_value (bool frc_str_conv = false) const; + Matrix matrix_value (bool frc_str_conv = false) const; + Complex complex_value (bool frc_str_conv = false) const; + ComplexMatrix complex_matrix_value (bool frc_str_conv = false) const; + charMatrix char_matrix_value (bool frc_str_conv = false) const; + charMatrix all_strings (void) const; + string string_value (void) const; + Range range_value (void) const; + Octave_map map_value (void) const; - double double_value (int frc_str_conv = 0) const; - Matrix matrix_value (int frc_str_conv = 0) const; - Complex complex_value (int frc_str_conv = 0) const; - ComplexMatrix complex_matrix_value (int frc_str_conv = 0) const; - charMatrix char_matrix_value (int frc_str_conv = 0) const; - charMatrix all_strings (void) const; - string string_value (void) const; - Range range_value (void) const; - Octave_map map_value (void) const; + tree_constant& lookup_map_element (const string& name, + bool insert = false, + bool silent = false); + + ColumnVector vector_value (bool frc_str_conv = false, + bool frc_vec_conv = false) const; - tree_constant& lookup_map_element (const string& name, - int insert = 0, - int silent = 0); + ComplexColumnVector + complex_vector_value (bool frc_str_conv = false, + bool frc_vec_conv = false) const; - ColumnVector vector_value (int frc_str_conv = 0, - int frc_vec_conv = 0) const; + tree_constant convert_to_str (void) const; + + void convert_to_row_or_column_vector (void); + + void bump_value (tree_expression::type); - ComplexColumnVector complex_vector_value (int frc_str_conv = 0, - int frc_vec_conv = 0) const; + void resize (int i, int j); + void resize (int i, int j, double val); - tree_constant convert_to_str (void) const; + void stash_original_text (const string& s); - void convert_to_row_or_column_vector (void); - - void bump_value (tree_expression::type); + void maybe_mutate (void); - void resize (int i, int j); - void resize (int i, int j, double val); + void print (void); + void print (ostream& os); - void stash_original_text (const string& s); + void print_code (ostream& os); - void maybe_mutate (void); + void gripe_wrong_type_arg (const char *name, + const tree_constant_rep& tcr) const; - void print (void); - void print (ostream& os); - - void print_code (ostream& os); + char *type_as_string (void) const; - void gripe_wrong_type_arg (const char *name, - const tree_constant_rep& tcr) const; + // Binary and unary operations. - char *type_as_string (void) const; - - // Binary and unary operations. + friend tree_constant do_binary_op (tree_constant& a, tree_constant& b, + tree_expression::type t); - friend tree_constant do_binary_op (tree_constant& a, tree_constant& b, - tree_expression::type t); + friend tree_constant do_unary_op (tree_constant& a, + tree_expression::type t); - friend tree_constant do_unary_op (tree_constant& a, - tree_expression::type t); + // We want to eliminate this. - // We want to eliminate this. + constant_type const_type (void) const { return type_tag; } + + // We want to get rid of these too: - constant_type const_type (void) const { return type_tag; } + void force_numeric (bool frc_str_conv = false); + tree_constant make_numeric (bool frc_str_conv = false) const; - // We want to get rid of these too: + // But not this. - void force_numeric (int frc_str_conv = 0); - tree_constant make_numeric (int frc_str_conv = 0) const; + void convert_to_matrix_type (bool make_complex); - // But not this. + // Indexing and assignment. - void convert_to_matrix_type (int make_complex); + void clear_index (void); - // Indexing and assignment. - - void clear_index (void); + // void set_index (double d); + void set_index (const Range& r); + void set_index (const ColumnVector& v); + void set_index (const Matrix& m); + void set_index (char c); - // void set_index (double d); - void set_index (const Range& r); - void set_index (const ColumnVector& v); - void set_index (const Matrix& m); - void set_index (char c); + void set_index (const Octave_object& args, + bool rhs_is_complex = false); - void set_index (const Octave_object& args, int rhs_is_complex = 0); + tree_constant do_index (const Octave_object& args); - tree_constant do_index (const Octave_object& args); + void maybe_widen (constant_type t); - void maybe_widen (constant_type t); + void assign (tree_constant& rhs, const Octave_object& args); - void assign (tree_constant& rhs, const Octave_object& args); + bool print_as_scalar (void); - int print_as_scalar (void); + bool print_as_structure (void); - int print_as_structure (void); - - // Data. + // Data. - union - { - double scalar; // A real scalar constant. - Matrix *matrix; // A real matrix constant. - Complex *complex_scalar; // A real scalar constant. - ComplexMatrix *complex_matrix; // A real matrix constant. - charMatrix *char_matrix; // A character string constant. - Range *range; // A set of evenly spaced values. - Octave_map *a_map; // An associative array. + union + { + double scalar; // A real scalar constant. + Matrix *matrix; // A real matrix constant. + Complex *complex_scalar; // A real scalar constant. + ComplexMatrix *complex_matrix; // A real matrix constant. + charMatrix *char_matrix; // A character string constant. + Range *range; // A set of evenly spaced values. + Octave_map *a_map; // An associative array. - tree_constant_rep *freeptr; // For custom memory management. - }; + tree_constant_rep *freeptr; // For custom memory management. + }; - constant_type type_tag; + constant_type type_tag; - int count; + int count; - string orig_text; - }; + string orig_text; + }; union { @@ -398,7 +398,7 @@ : tree_fvc (l, c) { rep = new tree_constant_rep (s); rep->count = 1; } - tree_constant (const charMatrix& chm, int is_string = 0) : tree_fvc () + tree_constant (const charMatrix& chm, bool is_string = false) : tree_fvc () { rep = new tree_constant_rep (chm, is_string); rep->count = 1; } tree_constant (double base, double limit, double inc) : tree_fvc () @@ -472,7 +472,7 @@ // Type. It would be nice to eliminate the need for this. - int is_constant (void) const { return 1; } + bool is_constant (void) const { return true; } // Size. @@ -483,22 +483,22 @@ // it is sometimes more natural to write is_undefined() instead of // ! is_defined(). - int is_defined (void) const { return rep->is_defined (); } - int is_undefined (void) const { return rep->is_undefined (); } + bool is_defined (void) const { return rep->is_defined (); } + bool is_undefined (void) const { return rep->is_undefined (); } // Is this constant a particular type, or does it belong to a // particular class of types? - int is_unknown (void) const { return rep->is_unknown (); } - int is_real_scalar (void) const { return rep->is_real_scalar (); } - int is_real_matrix (void) const { return rep->is_real_matrix (); } - int is_complex_scalar (void) const { return rep->is_complex_scalar (); } - int is_complex_matrix (void) const { return rep->is_complex_matrix (); } - int is_string (void) const { return rep->is_string (); } - int is_range (void) const { return rep->is_range (); } - int is_map (void) const { return rep->is_map (); } - int is_magic_colon (void) const { return rep->is_magic_colon (); } - int is_all_va_args (void) const { return rep->is_all_va_args (); } + bool is_unknown (void) const { return rep->is_unknown (); } + bool is_real_scalar (void) const { return rep->is_real_scalar (); } + bool is_real_matrix (void) const { return rep->is_real_matrix (); } + bool is_complex_scalar (void) const { return rep->is_complex_scalar (); } + bool is_complex_matrix (void) const { return rep->is_complex_matrix (); } + bool is_string (void) const { return rep->is_string (); } + bool is_range (void) const { return rep->is_range (); } + bool is_map (void) const { return rep->is_map (); } + bool is_magic_colon (void) const { return rep->is_magic_colon (); } + bool is_all_va_args (void) const { return rep->is_all_va_args (); } // Are any or all of the elements in this constant nonzero? @@ -507,34 +507,34 @@ // Other type stuff. - int is_real_type (void) const { return rep->is_real_type (); } + bool is_real_type (void) const { return rep->is_real_type (); } - int is_complex_type (void) const { return rep->is_complex_type (); } + bool is_complex_type (void) const { return rep->is_complex_type (); } - int is_scalar_type (void) const { return rep->is_scalar_type (); } - int is_matrix_type (void) const { return rep->is_matrix_type (); } + bool is_scalar_type (void) const { return rep->is_scalar_type (); } + bool is_matrix_type (void) const { return rep->is_matrix_type (); } - int is_numeric_type (void) const + bool is_numeric_type (void) const { return rep->is_numeric_type (); } - int valid_as_scalar_index (void) const + bool valid_as_scalar_index (void) const { return rep->valid_as_scalar_index (); } - int valid_as_zero_index (void) const + bool valid_as_zero_index (void) const { return rep->valid_as_zero_index (); } // Does this constant correspond to a truth value? - int is_true (void) const { return rep->is_true (); } + bool is_true (void) const { return rep->is_true (); } // Is at least one of the dimensions of this constant zero? - int is_empty (void) const + bool is_empty (void) const { return rep->is_empty (); } // Are the dimensions of this constant zero by zero? - int is_zero_by_zero (void) const + bool is_zero_by_zero (void) const { return ((! (is_magic_colon () || is_all_va_args () || is_unknown ())) && rows () == 0 && columns () == 0); @@ -542,19 +542,19 @@ // Values. - double double_value (int frc_str_conv = 0) const + double double_value (bool frc_str_conv = false) const { return rep->double_value (frc_str_conv); } - Matrix matrix_value (int frc_str_conv = 0) const + Matrix matrix_value (bool frc_str_conv = false) const { return rep->matrix_value (frc_str_conv); } - Complex complex_value (int frc_str_conv = 0) const + Complex complex_value (bool frc_str_conv = false) const { return rep->complex_value (frc_str_conv); } - ComplexMatrix complex_matrix_value (int frc_str_conv = 0) const + ComplexMatrix complex_matrix_value (bool frc_str_conv = false) const { return rep->complex_matrix_value (frc_str_conv); } - charMatrix char_matrix_value (int frc_str_conv = 0) const + charMatrix char_matrix_value (bool frc_str_conv = false) const { return rep->char_matrix_value (frc_str_conv); } charMatrix all_strings (void) const @@ -568,18 +568,21 @@ Octave_map map_value (void) const; - tree_constant lookup_map_element (const string& ref, int insert = 0, - int silent = 0); + tree_constant lookup_map_element (const string& ref, + bool insert = false, + bool silent = false); tree_constant lookup_map_element (SLList& list, - int insert = 0, int silent = 0); + bool insert = false, + bool silent = false); - ColumnVector vector_value (int /* frc_str_conv */ = 0, - int /* frc_vec_conv */ = 0) const + ColumnVector vector_value (bool /* frc_str_conv */ = false, + bool /* frc_vec_conv */ = false) const { return rep->vector_value (); } - ComplexColumnVector complex_vector_value (int /* frc_str_conv */ = 0, - int /* frc_vec_conv */ = 0) const + ComplexColumnVector + complex_vector_value (bool /* frc_str_conv */ = false, + bool /* frc_vec_conv */ = false) const { return rep->complex_vector_value (); } // Binary and unary operations. @@ -617,14 +620,14 @@ void print (void); void print (ostream& os) { rep->print (os); } - void print_with_name (const string& name, int print_padding = 1); + void print_with_name (const string& name, bool print_padding = true); void print_with_name (ostream& os, const string& name, - int print_padding = 1); + bool print_padding = true); // Evaluate this constant, possibly converting complex to real, or // matrix to scalar, etc. - tree_constant eval (int print_result) + tree_constant eval (bool print_result) { if (print_result) { @@ -635,7 +638,7 @@ return *this; } - Octave_object eval (int, int, const Octave_object&); + Octave_object eval (bool, int, const Octave_object&); // Store the original text corresponding to this constant for later // pretty printing. @@ -663,17 +666,17 @@ tree_constant_rep::constant_type const_type (void) const { return rep->const_type (); } - void convert_to_matrix_type (int make_complex) + void convert_to_matrix_type (bool make_complex) { rep->convert_to_matrix_type (make_complex); } // Can we make these go away? // These need better names, since a range really is a numeric type. - void force_numeric (int frc_str_conv = 0) + void force_numeric (bool frc_str_conv = false) { rep->force_numeric (frc_str_conv); } - tree_constant make_numeric (int frc_str_conv = 0) const + tree_constant make_numeric (bool frc_str_conv = false) const { if (is_numeric_type ()) return *this; @@ -681,9 +684,9 @@ return rep->make_numeric (frc_str_conv); } - int print_as_scalar (void) { return rep->print_as_scalar (); } + bool print_as_scalar (void) { return rep->print_as_scalar (); } - int print_as_structure (void) { return rep->print_as_structure (); } + bool print_as_structure (void) { return rep->print_as_structure (); } }; #endif diff --git a/src/pt-exp-base.cc b/src/pt-exp-base.cc --- a/src/pt-exp-base.cc +++ b/src/pt-exp-base.cc @@ -1,7 +1,7 @@ // pt-exp-base.cc -*- C++ -*- /* -Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton +Copyright (C) 1996 John W. Eaton This file is part of Octave. @@ -40,12 +40,12 @@ // Expressions. -int +bool tree_expression::is_logically_true (const char *warn_for) { - int expr_value = 0; + bool expr_value = false; - tree_constant t1 = eval (0); + tree_constant t1 = eval (false); if (! error_state) { @@ -75,7 +75,7 @@ if (! error_state) { if (t1.is_real_scalar ()) - expr_value = (int) t1.double_value (); + expr_value = t1.double_value () != 0.0; else if (t1.is_complex_scalar ()) expr_value = t1.complex_value () != 0.0; else @@ -101,7 +101,7 @@ } tree_constant -tree_expression::eval (int /* print */) +tree_expression::eval (bool /* print */) { panic ("invalid evaluation of generic expression"); return tree_constant (); diff --git a/src/pt-exp-base.h b/src/pt-exp-base.h --- a/src/pt-exp-base.h +++ b/src/pt-exp-base.h @@ -1,7 +1,7 @@ // pt-exp-base.h -*- C++ -*- /* -Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton +Copyright (C) 1996 John W. Eaton This file is part of Octave. @@ -82,38 +82,38 @@ virtual ~tree_expression (void) { } - virtual int is_constant (void) const - { return 0; } + virtual bool is_constant (void) const + { return false; } - virtual int is_matrix_constant (void) const - { return 0; } + virtual bool is_matrix_constant (void) const + { return false; } - virtual int is_range_constant (void) const - { return 0; } + virtual bool is_range_constant (void) const + { return false; } - virtual int is_multi_val_ret_expression (void) const - { return 0; } + virtual bool is_multi_val_ret_expression (void) const + { return false; } - virtual int is_identifier (void) const - { return 0; } + virtual bool is_identifier (void) const + { return false; } - virtual int is_indirect_ref (void) const - { return 0; } + virtual bool is_indirect_ref (void) const + { return false; } - virtual int is_index_expression (void) const - { return 0; } + virtual bool is_index_expression (void) const + { return false; } - virtual int is_assignment_expression (void) const - { return 0; } + virtual bool is_assignment_expression (void) const + { return false; } - virtual int is_prefix_expression (void) const - { return 0; } + virtual bool is_prefix_expression (void) const + { return false; } - virtual int is_logically_true (const char *); + virtual bool is_logically_true (const char *); virtual void mark_for_possible_ans_assign (void); - virtual tree_constant eval (int print) = 0; + virtual tree_constant eval (bool print) = 0; protected: type etype; diff --git a/src/pt-exp.cc b/src/pt-exp.cc --- a/src/pt-exp.cc +++ b/src/pt-exp.cc @@ -1,7 +1,7 @@ // pt-exp.cc -*- C++ -*- /* -Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton +Copyright (C) 1996 John W. Eaton This file is part of Octave. @@ -61,7 +61,7 @@ } tree_constant -tree_prefix_expression::eval (int print) +tree_prefix_expression::eval (bool print) { tree_constant retval; @@ -145,7 +145,7 @@ } tree_constant -tree_postfix_expression::eval (int print) +tree_postfix_expression::eval (bool print) { tree_constant retval; @@ -219,7 +219,7 @@ // Unary expressions. tree_constant -tree_unary_expression::eval (int /* print */) +tree_unary_expression::eval (bool /* print */) { if (error_state) return tree_constant (); @@ -234,7 +234,7 @@ case tree_expression::transpose: if (op) { - tree_constant u = op->eval (0); + tree_constant u = op->eval (false); if (error_state) eval_error (); else if (u.is_defined ()) @@ -337,7 +337,7 @@ // Binary expressions. tree_constant -tree_binary_expression::eval (int /* print */) +tree_binary_expression::eval (bool /* print */) { if (error_state) return tree_constant (); @@ -366,12 +366,12 @@ case tree_expression::or: if (op1) { - tree_constant a = op1->eval (0); + tree_constant a = op1->eval (false); if (error_state) eval_error (); else if (a.is_defined () && op2) { - tree_constant b = op2->eval (0); + tree_constant b = op2->eval (false); if (error_state) eval_error (); else if (b.is_defined ()) @@ -391,17 +391,17 @@ case tree_expression::and_and: case tree_expression::or_or: { - int result = 0; + bool result = false; if (op1) { - tree_constant a = op1->eval (0); + tree_constant a = op1->eval (false); if (error_state) { eval_error (); break; } - int a_true = a.is_true (); + bool a_true = a.is_true (); if (error_state) { eval_error (); @@ -412,7 +412,7 @@ { if (etype == tree_expression::or_or) { - result = 1; + result = true; goto done; } } @@ -420,14 +420,14 @@ { if (etype == tree_expression::and_and) { - result = 0; + result = false; goto done; } } if (op2) { - tree_constant b = op2->eval (0); + tree_constant b = op2->eval (false); if (error_state) { eval_error (); @@ -583,7 +583,7 @@ // Simple assignment expressions. tree_simple_assignment_expression::tree_simple_assignment_expression - (tree_identifier *i, tree_expression *r, int plhs, int ans_assign, + (tree_identifier *i, tree_expression *r, bool plhs, bool ans_assign, int l, int c) : tree_expression (l, c) { @@ -593,8 +593,8 @@ } tree_simple_assignment_expression::tree_simple_assignment_expression - (tree_index_expression *idx_expr, tree_expression *r, int plhs, - int ans_assign, int l, int c) + (tree_index_expression *idx_expr, tree_expression *r, bool plhs, + bool ans_assign, int l, int c) : tree_expression (l, c) { init (plhs, ans_assign); @@ -617,7 +617,7 @@ delete rhs; } -int +bool tree_simple_assignment_expression::left_hand_side_is_identifier_only (void) { return lhs->is_identifier_only (); @@ -630,7 +630,7 @@ } tree_constant -tree_simple_assignment_expression::eval (int print) +tree_simple_assignment_expression::eval (bool print) { assert (etype == tree_expression::assignment); @@ -641,7 +641,7 @@ if (rhs) { - tree_constant rhs_val = rhs->eval (0); + tree_constant rhs_val = rhs->eval (false); if (error_state) { eval_error (); @@ -694,6 +694,7 @@ { int l = line (); int c = column (); + if (l != -1 && c != -1) ::error ("evaluating assignment expression near line %d, column %d", l, c); @@ -732,11 +733,11 @@ // Colon expressions. -int +bool tree_colon_expression::is_range_constant (void) const { - int tmp = (op1 && op1->is_constant () - && op2 && op2->is_constant ()); + bool tmp = (op1 && op1->is_constant () + && op2 && op2->is_constant ()); return op3 ? (tmp && op3->is_constant ()) : tmp; } @@ -758,14 +759,14 @@ } tree_constant -tree_colon_expression::eval (int /* print */) +tree_colon_expression::eval (bool /* print */) { tree_constant retval; if (error_state || ! op1 || ! op2) return retval; - tree_constant tmp = op1->eval (0); + tree_constant tmp = op1->eval (false); if (tmp.is_undefined ()) { @@ -782,7 +783,7 @@ return retval; } - tmp = op2->eval (0); + tmp = op2->eval (false); if (tmp.is_undefined ()) { @@ -802,7 +803,7 @@ double inc = 1.0; if (op3) { - tmp = op3->eval (0); + tmp = op3->eval (false); if (tmp.is_undefined ()) { diff --git a/src/pt-exp.h b/src/pt-exp.h --- a/src/pt-exp.h +++ b/src/pt-exp.h @@ -1,7 +1,7 @@ -// tree-exp.h -*- C++ -*- +// pt-exp.h -*- C++ -*- /* -Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton +Copyright (C) 1996 John W. Eaton This file is part of Octave. @@ -52,12 +52,12 @@ ~tree_prefix_expression (void); - tree_constant eval (int print); + tree_constant eval (bool print); void eval_error (void); - int is_prefix_expression (void) const - { return 1; } + bool is_prefix_expression (void) const + { return true; } char *oper (void) const; @@ -82,7 +82,7 @@ ~tree_postfix_expression (void); - tree_constant eval (int print); + tree_constant eval (bool print); void eval_error (void); @@ -110,7 +110,7 @@ ~tree_unary_expression (void) { delete op; } - tree_constant eval (int print); + tree_constant eval (bool print); void eval_error (void); @@ -141,7 +141,7 @@ delete op2; } - tree_constant eval (int print); + tree_constant eval (bool print); void eval_error (void); @@ -160,7 +160,7 @@ tree_simple_assignment_expression : public tree_expression { private: - void init (int plhs, int ans_assign) + void init (bool plhs, bool ans_assign) { etype = tree_expression::assignment; lhs_idx_expr = 0; @@ -172,19 +172,22 @@ } public: - tree_simple_assignment_expression (int plhs = 0, int ans_assign = 0, + tree_simple_assignment_expression (bool plhs = false, + bool ans_assign = false, int l = -1, int c = -1) : tree_expression (l, c) { init (plhs, ans_assign); } tree_simple_assignment_expression (tree_identifier *i, tree_expression *r, - int plhs = 0, int ans_assign = 0, + bool plhs = false, + bool ans_assign = false, int l = -1, int c = -1); tree_simple_assignment_expression (tree_indirect_ref *i, tree_expression *r, - int plhs = 0, int ans_assign = 0, + bool plhs = false, + bool ans_assign = false, int l = -1, int c = -1) : tree_expression (l, c) { @@ -195,22 +198,23 @@ tree_simple_assignment_expression (tree_index_expression *idx_expr, tree_expression *r, - int plhs = 0, int ans_assign = 0, + bool plhs = false, + bool ans_assign = false, int l = -1, int c = -1); ~tree_simple_assignment_expression (void); - int left_hand_side_is_identifier_only (void); + bool left_hand_side_is_identifier_only (void); tree_identifier *left_hand_side_id (void); - int is_ans_assign (void) + bool is_ans_assign (void) { return ans_ass; } - tree_constant eval (int print); + tree_constant eval (bool print); - int is_assignment_expression (void) const - { return 1; } + bool is_assignment_expression (void) const + { return true; } void eval_error (void); @@ -221,8 +225,8 @@ tree_indirect_ref *lhs; tree_argument_list *index; tree_expression *rhs; - int preserve; - int ans_ass; + bool preserve; + bool ans_ass; }; // Colon expressions. @@ -247,11 +251,11 @@ delete op3; } - int is_range_constant (void) const; + bool is_range_constant (void) const; tree_colon_expression *chain (tree_expression *t); - tree_constant eval (int print); + tree_constant eval (bool print); void eval_error (const char *s); diff --git a/src/pt-fcn.cc b/src/pt-fcn.cc --- a/src/pt-fcn.cc +++ b/src/pt-fcn.cc @@ -1,7 +1,7 @@ // pt-fcn.cc -*- C++ -*- /* -Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton +Copyright (C) 1996 John W. Eaton This file is part of Octave. @@ -152,7 +152,7 @@ system_fcn_file = 0; } -int +bool tree_function::takes_varargs (void) const { return (param_list && param_list->takes_varargs ()); @@ -186,7 +186,7 @@ return retval; } -int +bool tree_function::takes_var_return (void) const { return (ret_list && ret_list->takes_varargs ()); @@ -207,7 +207,7 @@ } tree_constant -tree_function::eval (int print) +tree_function::eval (bool print) { tree_constant retval; @@ -248,7 +248,7 @@ } Octave_object -tree_function::eval (int /* print */, int nargout, const Octave_object& args) +tree_function::eval (bool /* print */, int nargout, const Octave_object& args) { Octave_object retval; @@ -325,7 +325,7 @@ { bind_nargin_and_nargout (nargin, nargout); - int echo_commands + bool echo_commands = (user_pref.echo_executing_commands & ECHO_FUNCTIONS); if (echo_commands) @@ -333,7 +333,7 @@ // Evaluate the commands that make up the function. - int pf = ! user_pref.silent_functions; + bool pf = ! user_pref.silent_functions; tree_constant last_computed_value = cmd_list->eval (pf); if (echo_commands) diff --git a/src/pt-fcn.h b/src/pt-fcn.h --- a/src/pt-fcn.h +++ b/src/pt-fcn.h @@ -1,7 +1,7 @@ // pt-fcn.h -*- C++ -*- /* -Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton +Copyright (C) 1996 John W. Eaton This file is part of Octave. @@ -100,10 +100,10 @@ void mark_as_system_fcn_file (void); - int is_system_fcn_file (void) const + bool is_system_fcn_file (void) const { return system_fcn_file; } - int takes_varargs (void) const; + bool takes_varargs (void) const; void octave_va_start (void) { curr_va_arg_number = num_named_args; } @@ -112,7 +112,7 @@ Octave_object octave_all_va_args (void); - int takes_var_return (void) const; + bool takes_var_return (void) const; void octave_vr_val (const tree_constant& val); @@ -121,9 +121,9 @@ string function_name (void) { return fcn_name; } - tree_constant eval (int print); + tree_constant eval (bool print); - Octave_object eval (int print, int nargout, const Octave_object& args); + Octave_object eval (bool print, int nargout, const Octave_object& args); void traceback_error (void); @@ -138,7 +138,7 @@ string file_name; string fcn_name; time_t t_parsed; - int system_fcn_file; + bool system_fcn_file; int num_named_args; Octave_object args_passed; int num_args_passed; diff --git a/src/pt-fvc-base.cc b/src/pt-fvc-base.cc --- a/src/pt-fvc-base.cc +++ b/src/pt-fvc-base.cc @@ -1,7 +1,7 @@ // pt-fvc-base.cc -*- C++ -*- /* -Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton +Copyright (C) 1996 John W. Eaton This file is part of Octave. @@ -62,7 +62,7 @@ } tree_constant -tree_fvc::lookup_map_element (SLList&, int, int) +tree_fvc::lookup_map_element (SLList&, bool, bool) { static tree_constant retval; @@ -85,7 +85,7 @@ } int -tree_fvc::save (ostream&, int, int) +tree_fvc::save (ostream&, bool, int) { panic_impossible (); return 0; diff --git a/src/pt-fvc-base.h b/src/pt-fvc-base.h --- a/src/pt-fvc-base.h +++ b/src/pt-fvc-base.h @@ -1,7 +1,7 @@ // pt-fvc-base.h -*- C++ -*- /* -Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton +Copyright (C) 1996 John W. Eaton This file is part of Octave. @@ -59,17 +59,18 @@ virtual void bump_value (tree_expression::type); virtual tree_constant lookup_map_element (SLList& list, - int insert = 0, int silent = 0); + bool insert = false, + bool silent = false); virtual string fcn_file_name (void) { return string (); } virtual time_t time_parsed (void); - virtual int is_system_fcn_file (void) const - { return 0; } + virtual bool is_system_fcn_file (void) const + { return false; } - virtual int save (ostream& /* os */, int /* mark_as_global */ = 0, + virtual int save (ostream& /* os */, bool /* mark_as_global */ = false, int /* precision */ = 17); }; diff --git a/src/pt-fvc.cc b/src/pt-fvc.cc --- a/src/pt-fvc.cc +++ b/src/pt-fvc.cc @@ -1,7 +1,7 @@ // pt-fvc.cc -*- C++ -*- /* -Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton +Copyright (C) 1996 John W. Eaton This file is part of Octave. @@ -47,44 +47,48 @@ // But first, some extra functions used by the tree classes. -static int +static bool any_element_less_than (const Matrix& a, double val) { int nr = a.rows (); int nc = a.columns (); + for (int j = 0; j < nc; j++) for (int i = 0; i < nr; i++) if (a.elem (i, j) < val) - return 1; - return 0; + return true; + + return false; } -static int +static bool any_element_greater_than (const Matrix& a, double val) { int nr = a.rows (); int nc = a.columns (); + for (int j = 0; j < nc; j++) for (int i = 0; i < nr; i++) if (a.elem (i, j) > val) - return 1; - return 0; + return true; + + return false; } // Make sure that all arguments have values. // Are any of the arguments `:'? -static int +static bool any_arg_is_magic_colon (const Octave_object& args) { int nargin = args.length (); for (int i = 0; i < nargin; i++) if (args(i).is_magic_colon ()) - return 1; + return true; - return 0; + return false; } // Symbols from the symbol table. @@ -276,7 +280,7 @@ return retval; } -int +bool tree_identifier::is_defined (void) { return (sym && sym->is_defined ()); @@ -306,6 +310,7 @@ { int l = line (); int c = column (); + if (l == -1 && c == -1) ::error ("`%s' undefined", name ().c_str ()); else @@ -329,7 +334,7 @@ // over .m files. tree_fvc * -tree_identifier::do_lookup (int& script_file_executed, int exec_script) +tree_identifier::do_lookup (bool& script_file_executed, bool exec_script) { script_file_executed = lookup (sym, exec_script); @@ -356,14 +361,14 @@ } tree_constant -tree_identifier::eval (int print) +tree_identifier::eval (bool print) { tree_constant retval; if (error_state) return retval; - int script_file_executed = 0; + bool script_file_executed = false; tree_fvc *object_to_eval = do_lookup (script_file_executed); @@ -382,7 +387,7 @@ retval = tmp(0); } else - retval = object_to_eval->eval (0); + retval = object_to_eval->eval (false); } else eval_undefined_error (); @@ -400,14 +405,14 @@ } Octave_object -tree_identifier::eval (int print, int nargout, const Octave_object& args) +tree_identifier::eval (bool print, int nargout, const Octave_object& args) { Octave_object retval; if (error_state) return retval; - int script_file_executed = 0; + bool script_file_executed = false; tree_fvc *object_to_eval = do_lookup (script_file_executed); @@ -514,7 +519,7 @@ } tree_constant -tree_indirect_ref::eval (int print) +tree_indirect_ref::eval (bool print) { tree_constant retval; @@ -527,7 +532,7 @@ } else { - int script_file_executed; + bool script_file_executed; tree_fvc *object_to_eval = id->do_lookup (script_file_executed, 0); @@ -546,7 +551,7 @@ } Octave_object -tree_indirect_ref::eval (int print, int nargout, const Octave_object& args) +tree_indirect_ref::eval (bool print, int nargout, const Octave_object& args) { Octave_object retval; @@ -559,7 +564,7 @@ } else { - int script_file_executed; + bool script_file_executed; tree_fvc *object_to_eval = id->do_lookup (script_file_executed, 0); @@ -629,7 +634,7 @@ } tree_constant -tree_builtin::eval (int /* print */) +tree_builtin::eval (bool /* print */) { tree_constant retval; @@ -664,7 +669,7 @@ static tree_constant apply_mapper_fcn (const tree_constant& arg, Mapper_fcn& m_fcn, - int /* print */) + bool /* print */) { tree_constant retval; @@ -750,7 +755,7 @@ } Octave_object -tree_builtin::eval (int /* print */, int nargout, const Octave_object& args) +tree_builtin::eval (bool /* print */, int nargout, const Octave_object& args) { Octave_object retval; diff --git a/src/pt-fvc.h b/src/pt-fvc.h --- a/src/pt-fvc.h +++ b/src/pt-fvc.h @@ -1,7 +1,7 @@ -// tree-fvc.h -*- C++ -*- +// pt-fvc.h -*- C++ -*- /* -Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton +Copyright (C) 1996 John W. Eaton This file is part of Octave. @@ -48,15 +48,15 @@ public: tree_identifier (int l = -1, int c = -1) - : tree_fvc (l, c), sym (0), maybe_do_ans_assign (0) { } + : tree_fvc (l, c), sym (0), maybe_do_ans_assign (false) { } tree_identifier (symbol_record *s, int l = -1, int c = -1) - : tree_fvc (l, c), sym (s), maybe_do_ans_assign (0) { } + : tree_fvc (l, c), sym (s), maybe_do_ans_assign (false) { } ~tree_identifier (void) { } - int is_identifier (void) const - { return 1; } + bool is_identifier (void) const + { return true; } string name (void) const; @@ -72,22 +72,22 @@ tree_constant assign (SLList list, tree_constant& t, const Octave_object& args); - int is_defined (void); + bool is_defined (void); void bump_value (tree_expression::type); - tree_fvc *do_lookup (int& script_file_executed, int exec_script = 1); + tree_fvc *do_lookup (bool& script_file_executed, bool exec_script = true); void link_to_global (void); void mark_as_formal_parameter (void); void mark_for_possible_ans_assign (void) - { maybe_do_ans_assign = 1; } + { maybe_do_ans_assign = true; } - tree_constant eval (int print); + tree_constant eval (bool print); - Octave_object eval (int print, int nargout, const Octave_object& args); + Octave_object eval (bool print, int nargout, const Octave_object& args); void eval_undefined_error (void); @@ -95,7 +95,7 @@ private: symbol_record *sym; - int maybe_do_ans_assign; + bool maybe_do_ans_assign; }; // Indirect references to values (structure references). @@ -105,26 +105,26 @@ { public: tree_indirect_ref (int l = -1, int c = -1) - : tree_fvc (l, c), id (0), preserve_ident (0) { } + : tree_fvc (l, c), id (0), preserve_ident (false) { } tree_indirect_ref (tree_identifier *i, int l = -1, int c = -1) - : tree_fvc (l, c), id (i), preserve_ident (0) { } + : tree_fvc (l, c), id (i), preserve_ident (false) { } ~tree_indirect_ref (void); tree_indirect_ref *chain (const string& s); - int is_indirect_ref (void) const - { return 1; } + bool is_indirect_ref (void) const + { return true; } - int is_identifier_only (void) const + bool is_identifier_only (void) const { return (id && refs.empty ()); } tree_identifier *ident (void) { return id; } void preserve_identifier (void) - { preserve_ident = 1; } + { preserve_ident = true; } string name (void) const; @@ -134,16 +134,16 @@ void mark_for_possible_ans_assign (void) { id->mark_for_possible_ans_assign (); } - tree_constant eval (int print); + tree_constant eval (bool print); - Octave_object eval (int print, int nargout, const Octave_object& args); + Octave_object eval (bool print, int nargout, const Octave_object& args); void print_code (ostream& os); private: tree_identifier *id; SLList refs; - int preserve_ident; + bool preserve_ident; }; // Builtin functions. @@ -162,12 +162,12 @@ // int is_builtin (void) const; - int is_mapper_function (void) const + bool is_mapper_function (void) const { return is_mapper; } - tree_constant eval (int print); + tree_constant eval (bool print); - Octave_object eval (int print, int nargout, const Octave_object& args); + Octave_object eval (bool print, int nargout, const Octave_object& args); string name (void) const { return my_name; } @@ -175,7 +175,7 @@ void print_code (ostream& os); private: - int is_mapper; + bool is_mapper; Mapper_fcn mapper_fcn; Octave_builtin_fcn fcn; string my_name; diff --git a/src/pt-mat.cc b/src/pt-mat.cc --- a/src/pt-mat.cc +++ b/src/pt-mat.cc @@ -1,7 +1,7 @@ // pt-mat.cc -*- C++ -*- /* -Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton +Copyright (C) 1996 John W. Eaton This file is part of Octave. @@ -46,96 +46,339 @@ // constant matrices, but it allows us to construct matrices from // other matrices, variables, and functions. -tree_matrix::~tree_matrix (void) -{ - delete element; - delete next; -} +// But first, some internal classes that make our job much easier. -int -tree_matrix::is_matrix_constant (void) const +class +tm_row_const { - const tree_matrix *list = this; +private: + + class + tm_row_const_rep : public SLList + { + public: + + tm_row_const_rep (void) + : SLList (), count (1), nr (0), nc (0), + all_str (false), is_cmplx (false), ok (false) { } + + tm_row_const_rep (const tree_matrix_row& mr) + : SLList (), count (1), nr (0), nc (0), + all_str (false), is_cmplx (false), ok (false) + { init (mr); } + + ~tm_row_const_rep (void) { } + + int count; + + int nr; + int nc; - while (list) + bool all_str; + bool is_cmplx; + + bool ok; + + void init (const tree_matrix_row&); + + private: + + tm_row_const_rep (const tm_row_const_rep&); + + tm_row_const_rep& operator = + (const tm_row_const_rep&); + }; + +public: + + tm_row_const (void) : rep (0) { } + + tm_row_const (const tree_matrix_row& mr) + : rep (new tm_row_const_rep (mr)) { } + + tm_row_const (const tm_row_const& x) : rep (x.rep) { - tree_expression *elem = list->element; + if (rep) + rep->count++; + } + + tm_row_const& operator = (const tm_row_const& x) + { + if (this != &x && rep != x.rep) + { + if (rep && --rep->count == 0) + delete rep; - if (! elem->is_constant ()) - return 0; + rep = x.rep; + + if (rep) + rep->count++; + } - list = list->next; + return *this; + } + + ~tm_row_const (void) + { + if (rep && --rep->count == 0) + delete rep; } - return 1; + int rows (void) { return rep->nr; } + int cols (void) { return rep->nc; } + + bool all_strings (void) const { return rep->all_str; } + bool is_complex (void) const { return rep->is_cmplx; } + + tree_constant& operator () (Pix p) { return rep->operator () (p); } + + const tree_constant& operator () (Pix p) const + { return rep->operator () (p); } + + Pix first (void) const { return rep->first (); } + void next (Pix& p) const { rep->next (p); } + + operator void* () const + { + return (rep && rep->ok) ? (void *) -1 : (void *) 0; + } + +private: + + tm_row_const_rep *rep; +}; + +void +tm_row_const::tm_row_const_rep::init (const tree_matrix_row& mr) +{ + all_str = true; + + int empties_ok = user_pref.empty_list_elements_ok; + + bool first_elem = true; + + for (Pix p = mr.first (); p != 0; mr.next (p)) + { + tree_expression *elt = mr (p); + + tree_constant tmp = elt->eval (false); + + if (error_state || tmp.is_undefined ()) + break; + else + { + int this_elt_nr = tmp.rows (); + int this_elt_nc = tmp.columns (); + + if (this_elt_nr == 0 || this_elt_nc == 0) + { + if (empties_ok < 0) + warning ("empty matrix found in matrix list"); + else if (empties_ok == 0) + { + ::error ("empty matrix found in matrix list"); + break; + } + } + else + { + if (first_elem) + { + first_elem = false; + + nr = this_elt_nr; + } + else if (this_elt_nr != nr) + { + ::error ("number of rows must match"); + break; + } + + nc += this_elt_nc; + + append (tmp); + } + + if (all_str && ! tmp.is_string ()) + all_str = false; + + if (! is_cmplx && tmp.is_complex_type ()) + is_cmplx = true; + } + } + + ok = ! error_state; } -tree_matrix * -tree_matrix::chain (tree_expression *t, tree_matrix::dir d) +template class SLNode; +template class SLList; + +class +tm_const : public SLList +{ +public: + + tm_const (const tree_matrix& tm) + : SLList (), nr (0), nc (0), all_str (false), + is_cmplx (false), ok (false) + { init (tm); } + + ~tm_const (void) { } + + int rows (void) const { return nr; } + int cols (void) const { return nc; } + + bool all_strings (void) const { return all_str; } + bool is_complex (void) const { return is_cmplx; } + + operator void* () const { return ok ? (void *) -1 : (void *) 0; } + +private: + + int nr; + int nc; + + bool all_str; + bool is_cmplx; + + bool ok; + + tm_const (void); + + tm_const (const tm_const&); + + tm_const& operator = (const tm_const&); + + void init (const tree_matrix& tm); +}; + +void +tm_const::init (const tree_matrix& tm) { - tree_matrix *tmp = new tree_matrix (t, d); - tmp->next = this; - return tmp; + all_str = true; + + int empties_ok = user_pref.empty_list_elements_ok; + + bool first_elem = true; + + // Just eval and figure out if what we have is complex or all + // strings. We can't check columns until we know that this is a + // numeric matrix -- collections of strings can have elements of + // different lengths. + + for (Pix p = tm.first (); p != 0; tm.next (p)) + { + tree_matrix_row *elt = tm (p); + + tm_row_const tmp (*elt); + + if (tmp) + { + if (all_str && ! tmp.all_strings ()) + all_str = false; + + if (! is_cmplx && tmp.is_complex ()) + is_cmplx = true; + + append (tmp); + } + else + break; + } + + if (! error_state) + { + for (Pix p = first (); p != 0; next (p)) + { + tm_row_const elt = this->operator () (p); + + int this_elt_nr = elt.rows (); + int this_elt_nc = elt.cols (); + + if (this_elt_nr == 0 || this_elt_nc == 0) + { + if (empties_ok < 0) + warning ("empty matrix found in matrix list"); + else if (empties_ok == 0) + { + ::error ("empty matrix found in matrix list"); + break; + } + } + else + { + if (first_elem) + { + first_elem = false; + + nc = this_elt_nc; + } + else if (all_str) + { + if (this_elt_nc > nc) + nc = this_elt_nc; + } + else if (this_elt_nc != nc) + { + ::error ("number of columns must match"); + break; + } + + nr += this_elt_nr; + } + } + } + + ok = ! error_state; } -tree_matrix * -tree_matrix::reverse (void) +bool +tree_matrix_row::is_matrix_constant (void) const { - tree_matrix *list = this; - tree_matrix *next; - tree_matrix *prev = 0; + for (Pix p = first (); p != 0; next (p)) + { + tree_expression *elt = this->operator () (p); - while (list) - { - next = list->next; - list->next = prev; - prev = list; - list = next; + if (! elt->is_constant ()) + return false; } - return prev; -} -int -tree_matrix::length (void) -{ - tree_matrix *list = this; - int len = 0; - while (list) - { - len++; - list = list->next; - } - return len; + return true; } tree_return_list * -tree_matrix::to_return_list (void) +tree_matrix_row::to_return_list (void) { tree_return_list *retval = 0; - tree_matrix *list; + bool first_elem = true; - for (list = this; list; list = list->next) + for (Pix p = first (); p != 0; next (p)) { - tree_expression *elem = list->element; + tree_expression *elt = this->operator () (p); - int is_id = elem->is_identifier (); + bool is_id = elt->is_identifier (); - int is_idx_expr = elem->is_index_expression (); + bool is_idx_expr = elt->is_index_expression (); if (is_id || is_idx_expr) { tree_index_expression *idx_expr; + if (is_id) { - tree_identifier *id = (tree_identifier *) elem; + tree_identifier *id = (tree_identifier *) elt; idx_expr = new tree_index_expression (id); } else - idx_expr = (tree_index_expression *) elem; + idx_expr = (tree_index_expression *) elt; - if (list == this) - retval = new tree_return_list (idx_expr); + if (first_elem) + { + first_elem = false; + + retval = new tree_return_list (idx_expr); + } else retval->append (idx_expr); } @@ -150,320 +393,143 @@ return retval; } -// Just about as ugly as it gets. - -struct const_matrix_list +void +tree_matrix_row::print_code (ostream& os) { - tree_matrix::dir direction; - tree_constant elem; - int nr; - int nc; -}; + Pix p = first (); + + while (p) + { + tree_expression *elt = this->operator () (p); + + next (p); + + if (elt) + { + elt->print_code (os); + + if (p) + os << ", "; + } + } +} +bool +tree_matrix::is_matrix_constant (void) const +{ + for (Pix p = first (); p != 0; next (p)) + { + tree_matrix_row *elt = this->operator () (p); + + if (! elt->is_matrix_constant ()) + return false; + } + + return true; +} + +// Just about as ugly as it gets. // Less ugly than before, anyway. +// Looking better all the time. tree_constant -tree_matrix::eval (int /* print */) +tree_matrix::eval (bool /* print */) { tree_constant retval; - if (error_state) - return retval; + tm_const tmp (*this); - // Just count the elements without looking at them. - - int total_len = length (); + if (tmp) + { + int nr = tmp.rows (); + int nc = tmp.cols (); - // Easier to deal with this later instead of a tree_matrix - // structure. - - const_matrix_list *list = new const_matrix_list [total_len]; + Matrix m; + ComplexMatrix cm; + charMatrix chm; - // Stats we want to keep track of. + // Now, extract the values from the individual elements and + // insert them in the result matrix. - int all_strings = 1; - - int found_complex = 0; + bool all_strings = tmp.all_strings (); + bool found_complex = tmp.is_complex (); - int row_total = 0; - int col_total = 0; + if (all_strings) + chm.resize (nr, nc, 0); + else if (found_complex) + cm.resize (nr, nc, 0.0); + else + m.resize (nr, nc, 0.0); - int row_height = 0; - - int cols_this_row = 0; - - int first_row = 1; + int put_row = 0; - int empties_ok = user_pref.empty_list_elements_ok; - - tree_matrix *ptr = this; + for (Pix p = tmp.first (); p != 0; tmp.next (p)) + { + int put_col = 0; - // Stuff for the result matrix or string. Declared here so that we - // don't get warnings from gcc about the goto crossing the - // initialization of these values. + tm_row_const row = tmp (p); - int put_row = 0; - int put_col = 0; + for (Pix q = row.first (); q != 0; row.next (q)) + { + tree_constant elt = row (q); - int prev_nr = 0; - int prev_nc = 0; - - Matrix m; - ComplexMatrix cm; - charMatrix chm; - - // Eliminate empties and gather stats. + if (found_complex) + { + if (elt.is_real_scalar ()) + cm (put_row, put_col) = elt.double_value (); + else if (elt.is_real_matrix () || elt.is_range ()) + cm.insert (elt.matrix_value (), put_row, put_col); + else if (elt.is_complex_scalar ()) + cm (put_row, put_col) = elt.complex_value (); + else + { + ComplexMatrix cm_elt = elt.complex_matrix_value (); - int found_new_row_in_empties = 0; - - int len = 0; - for (int i = 0; i < total_len; i++) - { - tree_expression *elem = ptr->element; - if (! elem) - { - retval = tree_constant (Matrix ()); - goto done; - } + if (error_state) + goto done; - tree_constant tmp = elem->eval (0); - if (error_state || tmp.is_undefined ()) - { - retval = tree_constant (); - goto done; - } + cm.insert (cm_elt, put_row, put_col); + } + } + else + { + if (elt.is_real_scalar ()) + m (put_row, put_col) = elt.double_value (); + else if (elt.is_string () && all_strings) + { + charMatrix chm_elt = elt.all_strings (); - int nr = tmp.rows (); - int nc = tmp.columns (); + if (error_state) + goto done; - dir direct = ptr->direction; + chm.insert (chm_elt, put_row, put_col); + } + else + { + Matrix m_elt = elt.matrix_value (); + + if (error_state) + goto done; - if (nr == 0 || nc == 0) - { - if (empties_ok < 0) - warning ("empty matrix found in matrix list"); - else if (empties_ok == 0) - { - ::error ("empty matrix found in matrix list"); - retval = tree_constant (); - goto done; + m.insert (m_elt, put_row, put_col); + } + } + + if (all_strings && chm.rows () > 0 && chm.cols () > 0) + retval = tree_constant (chm, true); + else if (found_complex) + retval = cm; + else + retval = m; + + put_col += elt.columns (); } - if (direct == md_down) - found_new_row_in_empties = 1; - - goto next; - } - - if (found_new_row_in_empties) - { - found_new_row_in_empties = 0; - list[len].direction = md_down; - } - else - list[len].direction = direct; - - list[len].elem = tmp; - list[len].nr = nr; - list[len].nc = nc; - - if (all_strings && ! tmp.is_string ()) - all_strings = 0; - - if (! found_complex && tmp.is_complex_type ()) - found_complex = 1; - - len++; - - next: - - ptr = ptr->next; - } - - // if (all_strings) - // cerr << "all strings\n"; - - // Compute size of result matrix, and check to see that the dimensions - // of all the elements will match up properly. - - for (int i = 0; i < len; i++) - { - dir direct = list[i].direction; - - int nr = list[i].nr; - int nc = list[i].nc; - - if (i == 0) - { - row_total = nr; - col_total = nc; - - row_height = nr; - cols_this_row = nc; - } - else - { - switch (direct) - { - case md_right: - { - if (nr != row_height) - { - ::error ("number of rows must match"); - goto done; - } - else - { - cols_this_row += nc; - - if (first_row) - col_total = cols_this_row; - else if (all_strings && cols_this_row > col_total) - col_total = cols_this_row; - } - } - break; - - case md_down: - { - if (cols_this_row != col_total && ! all_strings) - { - ::error ("number of columns must match"); - goto done; - } - first_row = 0; - row_total += nr; - row_height = nr; - cols_this_row = nc; - } - break; - - default: - panic_impossible (); - break; - } + put_row += row.rows (); } } - // Don't forget to check to see if the last element will fit. - - if (all_strings && cols_this_row > col_total) - { - col_total = cols_this_row; - } - else if (cols_this_row != col_total) - { - ::error ("number of columns must match"); - goto done; - } - - // Now, extract the values from the individual elements and insert - // them in the result matrix. - - if (all_strings) - chm.resize (row_total, col_total, 0); - else if (found_complex) - cm.resize (row_total, col_total, 0.0); - else - m.resize (row_total, col_total, 0.0); - - for (int i = 0; i < len; i++) - { - tree_constant tmp = list[i].elem; - - int nr = list[i].nr; - int nc = list[i].nc; - - if (nr == 0 || nc == 0) - continue; - - if (i == 0) - { - put_row = 0; - put_col = 0; - } - else - { - switch (list[i].direction) - { - case md_right: - put_col += prev_nc; - break; - - case md_down: - put_row += prev_nr; - put_col = 0; - break; - - default: - panic_impossible (); - break; - } - } - - if (found_complex) - { - if (tmp.is_real_scalar ()) - { - cm (put_row, put_col) = tmp.double_value (); - } - else if (tmp.is_real_matrix () || tmp.is_range ()) - { - cm.insert (tmp.matrix_value (), put_row, put_col); - } - else if (tmp.is_complex_scalar ()) - { - cm (put_row, put_col) = tmp.complex_value (); - } - else - { - ComplexMatrix cm_tmp = tmp.complex_matrix_value (); - - if (error_state) - goto done; - - cm.insert (cm_tmp, put_row, put_col); - } - } - else - { - if (tmp.is_real_scalar ()) - { - m (put_row, put_col) = tmp.double_value (); - } - else if (tmp.is_string () && all_strings) - { - charMatrix chm_tmp = tmp.all_strings (); - - if (error_state) - goto done; - - chm.insert (chm_tmp, put_row, put_col); - } - else - { - Matrix m_tmp = tmp.matrix_value (); - - if (error_state) - goto done; - - m.insert (m_tmp, put_row, put_col); - } - } - - prev_nr = nr; - prev_nc = nc; - } - - if (all_strings && chm.rows () > 0 && chm.cols () > 0) - retval = tree_constant (chm, 1); - else if (found_complex) - retval = cm; - else - retval = m; - - done: - delete [] list; +done: return retval; } @@ -478,29 +544,20 @@ os << "["; - tree_matrix *list = this; + Pix p = first (); - while (list) + while (p) { - list->element->print_code (os); + tree_matrix_row *elt = this->operator () (p); - list = list->next; + next (p); - if (list) + if (elt) { - switch (list->direction) - { - case md_right: - os << ", "; - break; + elt->print_code (os); - case md_down: - os << "; "; - break; - - default: - break; - } + if (p) + os << "; "; } } diff --git a/src/pt-mat.h b/src/pt-mat.h --- a/src/pt-mat.h +++ b/src/pt-mat.h @@ -1,7 +1,7 @@ // pt-mat.h -*- C++ -*- /* -Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton +Copyright (C) 1996 John W. Eaton This file is part of Octave. @@ -33,47 +33,52 @@ class tree_constant; class tree_return_list; +#include + #include "pt-exp.h" // General matrices. This allows us to construct matrices from // other matrices, variables, and functions. class -tree_matrix : public tree_expression +tree_matrix_row : public SLList { public: - enum dir - { - md_none, - md_right, - md_down, - }; - - tree_matrix (void) - : tree_expression (), direction (tree_matrix::md_none), - element (0), next (0) { } - tree_matrix (tree_expression *e, tree_matrix::dir d) - : tree_expression (), direction (d), element (e), next (0) { } - - ~tree_matrix (void); + tree_matrix_row (tree_expression *e = 0) : SLList () + { + if (e) + append (e); + } - int is_matrix_constant (void) const; + ~tree_matrix_row (void) { } - tree_matrix *chain (tree_expression *e, tree_matrix::dir d); - tree_matrix *reverse (void); - int length (void); + bool is_matrix_constant (void) const; tree_return_list *to_return_list (void); - tree_constant eval (int print); + void print_code (ostream& os); +}; + +class +tree_matrix : public tree_expression, public SLList +{ +public: + + tree_matrix (tree_matrix_row *mr = 0) + : tree_expression (), SLList () + { + if (mr) + append (mr); + } + + ~tree_matrix (void) { } + + bool is_matrix_constant (void) const; + + tree_constant eval (bool print); void print_code (ostream& os); - -private: - tree_matrix::dir direction; // Direction from the previous element. - tree_expression *element; - tree_matrix *next; }; #endif diff --git a/src/pt-misc.cc b/src/pt-misc.cc --- a/src/pt-misc.cc +++ b/src/pt-misc.cc @@ -1,7 +1,7 @@ // pt-misc.cc -*- C++ -*- /* -Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton +Copyright (C) 1996 John W. Eaton This file is part of Octave. @@ -82,7 +82,7 @@ } void -tree_statement::maybe_echo_code (int in_function_body) +tree_statement::maybe_echo_code (bool in_function_body) { if (in_function_body && (user_pref.echo_executing_commands & ECHO_FUNCTIONS)) @@ -118,9 +118,9 @@ } tree_constant -tree_statement_list::eval (int print) +tree_statement_list::eval (bool print) { - int pf; + bool pf; tree_constant retval; if (error_state) @@ -130,8 +130,8 @@ { tree_statement *elt = this->operator () (p); - if (print == 0) - pf = 0; + if (! print) + pf = false; else pf = elt->print_flag; @@ -163,13 +163,13 @@ } Octave_object -tree_statement_list::eval (int print, int nargout) +tree_statement_list::eval (bool print, int nargout) { Octave_object retval; if (nargout > 1) { - int pf; + bool pf; if (error_state) return retval; @@ -178,8 +178,8 @@ { tree_statement *elt = this->operator () (p); - if (print == 0) - pf = 0; + if (! print) + pf = false; else pf = elt->print_flag; @@ -255,7 +255,7 @@ tree_expression *elt = this->operator () (p); if (elt) { - tree_constant tmp = elt->eval (0); + tree_constant tmp = elt->eval (false); if (error_state) { ::error ("evaluating argument list element number %d", k); @@ -403,7 +403,7 @@ tree_identifier *elt = this->operator () (p); if (elt->is_defined ()) - retval(i) = elt->eval (0); + retval(i) = elt->eval (false); i++; } @@ -420,10 +420,10 @@ return retval; } -int +bool tree_parameter_list::is_defined (void) { - int status = 1; + bool status = true; for (Pix p = first (); p != 0; next (p)) { @@ -431,7 +431,7 @@ if (! elt->is_defined ()) { - status = 0; + status = false; break; } } @@ -514,7 +514,7 @@ && (id = assign_expr->left_hand_side_id ())) { id->link_to_global (); - assign_expr->eval (0); + assign_expr->eval (false); } else error ("global: unable to make individual structure elements global"); @@ -578,7 +578,7 @@ if (is_else_clause () || expr->is_logically_true ("if")) { if (list) - list->eval (1); + list->eval (true); return 1; } @@ -623,7 +623,7 @@ { Pix p = first (); - int first_elt = 1; + bool first_elt = true; while (p) { @@ -644,7 +644,7 @@ elt->print_code (os); } - first_elt = 0; + first_elt = false; next (p); } } diff --git a/src/pt-misc.h b/src/pt-misc.h --- a/src/pt-misc.h +++ b/src/pt-misc.h @@ -1,7 +1,7 @@ // pt-misc.h -*- C++ -*- /* -Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton +Copyright (C) 1996 John W. Eaton This file is part of Octave. @@ -62,36 +62,36 @@ public: tree_statement (void) - : tree_print_code (), command (0), expression (0), print_flag (1) { } + : tree_print_code (), command (0), expression (0), print_flag (true) { } tree_statement (tree_command *c) - : tree_print_code (), command (c), expression (0), print_flag (1) { } + : tree_print_code (), command (c), expression (0), print_flag (true) { } tree_statement (tree_expression *e) - : tree_print_code (), command (0), expression (e), print_flag (1) { } + : tree_print_code (), command (0), expression (e), print_flag (true) { } ~tree_statement (void); - void set_print_flag (int print) + void set_print_flag (bool print) { print_flag = print; } - int is_command (void) + bool is_command (void) { return command != 0; } - int is_expression (void) + bool is_expression (void) { return expression != 0; } int line (void); int column (void); - void maybe_echo_code (int); + void maybe_echo_code (bool); void print_code (ostream& os); private: tree_command *command; // Command to execute. tree_expression *expression; // Command to execute. - int print_flag; // Print result of eval for this command? + bool print_flag; // Print result of eval for this command? }; class @@ -99,11 +99,11 @@ { public: tree_statement_list (void) - : SLList (), tree_print_code () - { function_body = 0; } + : SLList (), tree_print_code (), function_body (false) + { } tree_statement_list (tree_statement *s) - : SLList (), tree_print_code (), function_body (0) + : SLList (), tree_print_code (), function_body (false) { append (s); } ~tree_statement_list (void) @@ -115,16 +115,16 @@ } } - void mark_as_function_body (void) { function_body = 1; } + void mark_as_function_body (void) { function_body = true; } - tree_constant eval (int print); + tree_constant eval (bool print); - Octave_object eval (int print, int nargout); + Octave_object eval (bool print, int nargout); void print_code (ostream& os); private: - int function_body; + bool function_body; }; // Argument lists. Used to hold the list of expressions that are the @@ -181,20 +181,20 @@ void mark_varargs (void) { marked_for_varargs = 1; } - int takes_varargs (void) const - { return marked_for_varargs; } + bool takes_varargs (void) const + { return marked_for_varargs != 0; } void mark_varargs_only (void) { marked_for_varargs = -1; } - int varargs_only (void) + bool varargs_only (void) { return (marked_for_varargs < 0); } void initialize_undefined_elements (tree_constant& val); void define_from_arg_vector (const Octave_object& args); - int is_defined (void); + bool is_defined (void); Octave_object convert_to_const_vector (tree_va_return_list *vr_list); @@ -297,10 +297,8 @@ ~tree_if_clause (void); - int is_else_clause (void) - { - return ! expr; - } + bool is_else_clause (void) + { return ! expr; } int eval (void); diff --git a/src/pt-mvr-base.cc b/src/pt-mvr-base.cc --- a/src/pt-mvr-base.cc +++ b/src/pt-mvr-base.cc @@ -1,7 +1,7 @@ // pt-mvr-base.cc -*- C++ -*- /* -Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton +Copyright (C) 1996 John W. Eaton This file is part of Octave. @@ -36,7 +36,7 @@ // A base class for objects that can be return multiple values tree_constant -tree_multi_val_ret::eval (int /* print */) +tree_multi_val_ret::eval (bool /* print */) { panic ("invalid evaluation of generic expression"); return tree_constant (); diff --git a/src/pt-mvr-base.h b/src/pt-mvr-base.h --- a/src/pt-mvr-base.h +++ b/src/pt-mvr-base.h @@ -1,7 +1,7 @@ // pt-mvr-base.h -*- C++ -*- /* -Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton +Copyright (C) 1996 John W. Eaton This file is part of Octave. @@ -46,12 +46,12 @@ ~tree_multi_val_ret (void) { } - int is_multi_val_ret_expression (void) const - { return 1; } + bool is_multi_val_ret_expression (void) const + { return true; } - tree_constant eval (int print); + tree_constant eval (bool print); - virtual Octave_object eval (int print, int nargout, + virtual Octave_object eval (bool print, int nargout, const Octave_object& args) = 0; }; diff --git a/src/pt-mvr.cc b/src/pt-mvr.cc --- a/src/pt-mvr.cc +++ b/src/pt-mvr.cc @@ -1,7 +1,7 @@ // pt-mvr.cc -*- C++ -*- /* -Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton +Copyright (C) 1996 John W. Eaton This file is part of Octave. @@ -46,28 +46,28 @@ // Make sure that all arguments have values. -static int +static bool all_args_defined (const Octave_object& args) { int nargin = args.length (); for (int i = 0; i < nargin; i++) if (args(i).is_undefined ()) - return 0; + return false; - return 1; + return true; } // Used internally. tree_constant -tree_oct_obj::eval (int /* print */) +tree_oct_obj::eval (bool /* print */) { return values(0); } Octave_object -tree_oct_obj::eval (int /* print */, int /* nargout */, +tree_oct_obj::eval (bool /* print */, int /* nargout */, const Octave_object& /* args */) { return values; @@ -111,7 +111,7 @@ } tree_constant -tree_index_expression::eval (int print) +tree_index_expression::eval (bool print) { tree_constant retval; @@ -162,7 +162,7 @@ } Octave_object -tree_index_expression::eval (int print, int nargout, +tree_index_expression::eval (bool print, int nargout, const Octave_object& /* args */) { Octave_object retval; @@ -273,7 +273,7 @@ } tree_constant -tree_multi_assignment_expression::eval (int print) +tree_multi_assignment_expression::eval (bool print) { tree_constant retval; @@ -290,7 +290,7 @@ } Octave_object -tree_multi_assignment_expression::eval (int print, int nargout, +tree_multi_assignment_expression::eval (bool print, int nargout, const Octave_object& /* args */) { assert (etype == tree_expression::multi_assignment); @@ -311,8 +311,9 @@ if (results.length () > 0) { int i = 0; - int pad_after = 0; - int last_was_scalar_type = 0; + + bool pad_after = false; + for (Pix p = lhs->first (); p != 0; lhs->next (p)) { tree_index_expression *lhs_expr = lhs->operator () (p); @@ -336,7 +337,7 @@ tree_simple_assignment_expression tmp_expr (lhs_expr, tmp, 1, 0, ma_line, ma_column); - results(i) = tmp_expr.eval (0); // May change + results(i) = tmp_expr.eval (false); // May change if (error_state) break; @@ -351,7 +352,8 @@ if (print) results(i).print_with_name (lhs_expr->name (), 0); - pad_after++; + pad_after = true; + i++; } else @@ -359,15 +361,7 @@ tree_simple_assignment_expression tmp_expr (lhs_expr, 0, 1, 0, ma_line, ma_column); - tmp_expr.eval (0); - - if (error_state) - break; - - if (last_was_scalar_type && i == 1) - pad_after = 0; - - break; + tmp_expr.eval (false); } } diff --git a/src/pt-mvr.h b/src/pt-mvr.h --- a/src/pt-mvr.h +++ b/src/pt-mvr.h @@ -1,7 +1,7 @@ -// tree-mvr.h -*- C++ -*- +// pt-mvr.h -*- C++ -*- /* -Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton +Copyright (C) 1996 John W. Eaton This file is part of Octave. @@ -57,9 +57,9 @@ ~tree_oct_obj (void) { } - tree_constant eval (int print); + tree_constant eval (bool print); - Octave_object eval (int print, int nargout, const Octave_object& args); + Octave_object eval (bool print, int nargout, const Octave_object& args); void print_code (ostream&) { } @@ -90,8 +90,8 @@ ~tree_index_expression (void); - int is_index_expression (void) const - { return 1; } + bool is_index_expression (void) const + { return true; } tree_indirect_ref *ident (void) { return id; } @@ -103,9 +103,9 @@ void mark_for_possible_ans_assign (void); - tree_constant eval (int print); + tree_constant eval (bool print); - Octave_object eval (int print, int nargout, const Octave_object& args); + Octave_object eval (bool print, int nargout, const Octave_object& args); void eval_error (void); @@ -122,32 +122,32 @@ tree_multi_assignment_expression : public tree_multi_val_ret { public: - tree_multi_assignment_expression (int plhs = 0, int l = -1, int c = -1) + tree_multi_assignment_expression (bool plhs = false, int l = -1, int c = -1) : tree_multi_val_ret (l, c, tree_expression::multi_assignment), preserve (plhs), lhs (0), rhs (0) { } tree_multi_assignment_expression (tree_return_list *lst, tree_multi_val_ret *r, - int plhs = 0, + bool plhs = false, int l = -1, int c = -1) : tree_multi_val_ret (l, c, tree_expression::multi_assignment), preserve (plhs), lhs (lst), rhs (r) { } ~tree_multi_assignment_expression (void); - tree_constant eval (int print); + tree_constant eval (bool print); - Octave_object eval (int print, int nargout, const Octave_object& args); + Octave_object eval (bool print, int nargout, const Octave_object& args); - int is_assignment_expression (void) const - { return 1; } + bool is_assignment_expression (void) const + { return true; } void eval_error (void); void print_code (ostream& os); private: - int preserve; + bool preserve; tree_return_list *lhs; tree_multi_val_ret *rhs; }; diff --git a/src/pt-plot.cc b/src/pt-plot.cc --- a/src/pt-plot.cc +++ b/src/pt-plot.cc @@ -1,7 +1,7 @@ // pt-plot.cc -*- C++ -*- /* -Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton +Copyright (C) 1996 John W. Eaton This file is part of Octave. @@ -66,13 +66,13 @@ static int plot_line_count = 0; // Is this a parametric plot? Makes a difference for 3D plotting. -static int parametric_plot = 0; +static bool parametric_plot = false; // The gnuplot terminal type. static char *gnuplot_terminal_type = 0; // Should the graph window be cleared before plotting the next line? -static int clear_before_plotting = 1; +static bool clear_before_plotting = true; // List of files to delete when we exit or crash. static SLStack tmp_files; @@ -110,7 +110,7 @@ static void open_plot_stream (void) { - static int initialized = 0; + static bool initialized = false; if (plot_stream && ! *plot_stream) { @@ -120,7 +120,7 @@ if (! plot_stream) { - initialized = 0; + initialized = false; plot_line_count = 0; @@ -169,7 +169,7 @@ if (! error_state && plot_stream && *plot_stream && ! initialized) { - initialized = 1; + initialized = true; *plot_stream << "set data style lines\n"; if (gnuplot_terminal_type) @@ -196,9 +196,9 @@ int splot_len = strlen (GNUPLOT_COMMAND_SPLOT); int plot_len = strlen (GNUPLOT_COMMAND_PLOT); - int is_replot = (strncmp (cmd, GNUPLOT_COMMAND_REPLOT, replot_len) == 0); - int is_splot = (strncmp (cmd, GNUPLOT_COMMAND_SPLOT, splot_len) == 0); - int is_plot = (strncmp (cmd, GNUPLOT_COMMAND_PLOT, plot_len) == 0); + bool is_replot = (strncmp (cmd, GNUPLOT_COMMAND_REPLOT, replot_len) == 0); + bool is_splot = (strncmp (cmd, GNUPLOT_COMMAND_SPLOT, splot_len) == 0); + bool is_plot = (strncmp (cmd, GNUPLOT_COMMAND_PLOT, plot_len) == 0); if (plot_line_count == 0 && is_replot) error ("replot: no previous plot"); @@ -405,7 +405,7 @@ if (lower) { - tree_constant lower_val = lower->eval (0); + tree_constant lower_val = lower->eval (false); if (error_state) { ::error ("evaluating lower bound of plot range"); @@ -422,7 +422,7 @@ if (upper) { - tree_constant upper_val = upper->eval (0); + tree_constant upper_val = upper->eval (false); if (error_state) { ::error ("evaluating upper bound of plot range"); @@ -473,7 +473,7 @@ { if (x[i]) { - tree_constant tmp = x[i]->eval (0); + tree_constant tmp = x[i]->eval (false); if (error_state) { ::error ("evaluating plot using command"); @@ -600,7 +600,7 @@ if (linetype) { - tree_constant tmp = linetype->eval (0); + tree_constant tmp = linetype->eval (false); if (! error_state && tmp.is_defined ()) { double val = tmp.double_value (); @@ -621,7 +621,7 @@ if (pointtype) { - tree_constant tmp = pointtype->eval (0); + tree_constant tmp = pointtype->eval (false); if (! error_state && tmp.is_defined ()) { double val = tmp.double_value (); @@ -723,7 +723,7 @@ { if (plot_data) { - tree_constant data = plot_data->eval (0); + tree_constant data = plot_data->eval (false); if (! error_state && data.is_defined ()) { @@ -815,7 +815,7 @@ if (title_clause) { - tree_constant tmp = title_clause->eval (0); + tree_constant tmp = title_clause->eval (false); if (! error_state && tmp.is_string ()) plot_buf << " " << GNUPLOT_COMMAND_TITLE << " " << '"' << tmp.string_value () << '"'; @@ -913,7 +913,7 @@ } string -save_in_tmp_file (tree_constant& t, int ndim, int parametric) +save_in_tmp_file (tree_constant& t, int ndim, bool parametric) { string name = oct_tempnam (); @@ -1046,9 +1046,9 @@ case 2: if (argv[1] == "on") - clear_before_plotting = 0; + clear_before_plotting = false; else if (argv[1] == "off") - clear_before_plotting = 1; + clear_before_plotting = true; else print_usage ("hold"); break; @@ -1096,9 +1096,9 @@ if (argc > 1) { if (almost_match ("parametric", argv[1], 3)) - parametric_plot = 1; + parametric_plot = true; else if (almost_match ("noparametric", argv[1], 5)) - parametric_plot = 0; + parametric_plot = false; else if (almost_match ("term", argv[1], 1)) { delete [] gnuplot_terminal_type; diff --git a/src/pt-plot.h b/src/pt-plot.h --- a/src/pt-plot.h +++ b/src/pt-plot.h @@ -1,7 +1,7 @@ // pt-plot.h -*- C++ -*- /* -Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton +Copyright (C) 1996 John W. Eaton This file is part of Octave. @@ -79,7 +79,7 @@ ~plot_limits (void); - void print (int print, ostrstream& plot_buf); + void print (int ndim, ostrstream& plot_buf); void print_code (ostream& os); @@ -235,7 +235,7 @@ }; extern string save_in_tmp_file (tree_constant& t, int ndim = 2, - int parametric = 0); + bool parametric = false); extern void mark_for_deletion (const string&); diff --git a/src/variables.cc b/src/variables.cc --- a/src/variables.cc +++ b/src/variables.cc @@ -99,7 +99,7 @@ // Is this variable a builtin? -int +bool is_builtin_variable (const string& name) { symbol_record *sr = global_sym_tab->lookup (name, 0, 0); @@ -108,7 +108,7 @@ // Is this a text-style function? -int +bool is_text_function_name (const string& s) { symbol_record *sr = global_sym_tab->lookup (s); @@ -117,7 +117,7 @@ // Is this function globally in this scope? -int +bool is_globally_visible (const string& name) { symbol_record *sr = curr_sym_tab->lookup (name, 0, 0); @@ -762,10 +762,10 @@ return script_file_executed; } -static int +static bool load_fcn_from_file (symbol_record *sym_rec, int exec_script) { - int script_file_executed = 0; + bool script_file_executed = false; string nm = sym_rec->name (); @@ -799,10 +799,10 @@ return script_file_executed; } -int +bool lookup (symbol_record *sym_rec, int exec_script) { - int script_executed = 0; + bool script_executed = false; if (! sym_rec->is_linked_to_global ()) { @@ -1475,7 +1475,7 @@ // 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, 0, 1); + tree_simple_assignment_expression tmp_ass (ans_id, tmp, false, true); tmp_ass.eval (print); } diff --git a/src/variables.h b/src/variables.h --- a/src/variables.h +++ b/src/variables.h @@ -70,7 +70,7 @@ extern void initialize_symbol_tables (void); -extern int lookup (symbol_record *s, int exec_script = 1); +extern bool lookup (symbol_record *s, int exec_script = 1); extern symbol_record *lookup_by_name (const string& nm, int exec_script = 1); @@ -86,9 +86,9 @@ extern void force_link_to_function (const string&); -extern int is_builtin_variable (const string&); -extern int is_text_function_name (const string&); -extern int is_globally_visible (const string&); +extern bool is_builtin_variable (const string&); +extern bool is_text_function_name (const string&); +extern bool is_globally_visible (const string&); extern tree_fvc *is_valid_function (const tree_constant&, const string&, int warn = 0);