Mercurial > octave
changeset 23706:6683451b75b2
move Vstring_fill_char to tree_evaluator class
* pt-mat.h, pt-mat.cc (Vstring_fill_char): Delete.
* pt-eval.h, pt-eval.cc (tree_evaluator::m_string_fill_char):
New variable.
(tree_evaluator::string_fill_char): New functions.
(Fstring_fill_char): Move here from pt-mat.cc.
(tree_evaluator::visit_matrix): Use m_string_fill_char instead of
Vstring_fill_char.
* ov-usr-fcn.cc (octave_user_function::bind_automatic_vars):
Access string_fill_char through tree_evaluator.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 27 Jun 2017 06:41:42 -0400 |
parents | 4c597585ff52 |
children | b132881f9aff |
files | libinterp/octave-value/ov-usr-fcn.cc libinterp/parse-tree/pt-eval.cc libinterp/parse-tree/pt-eval.h libinterp/parse-tree/pt-mat.cc libinterp/parse-tree/pt-mat.h |
diffstat | 5 files changed, 76 insertions(+), 59 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/octave-value/ov-usr-fcn.cc Mon Jun 26 23:54:43 2017 -0400 +++ b/libinterp/octave-value/ov-usr-fcn.cc Tue Jun 27 06:41:42 2017 -0400 @@ -60,9 +60,6 @@ // Whether to optimize subsasgn method calls. static bool Voptimize_subsasgn_calls = true; -// The character to fill with when creating string arrays. -extern char Vstring_fill_char; // see pt-mat.cc - std::map<std::string, octave_value> octave_user_code::subfunctions (void) const { @@ -731,7 +728,8 @@ // which might be redefined in a function. Keep the old argn name // for backward compatibility of functions that use it directly. - m_scope->force_assign ("argn", charMatrix (arg_names, Vstring_fill_char)); + charMatrix chm (arg_names, tw.string_fill_char ()); + m_scope->force_assign ("argn", chm); m_scope->force_assign (".argn.", Cell (arg_names)); m_scope->mark_hidden (".argn.");
--- a/libinterp/parse-tree/pt-eval.cc Mon Jun 26 23:54:43 2017 -0400 +++ b/libinterp/parse-tree/pt-eval.cc Tue Jun 27 06:41:42 2017 -0400 @@ -1471,7 +1471,7 @@ else maybe_warn_string_concat (all_dq_strings_p, all_sq_strings_p); - charNDArray result (dv, Vstring_fill_char); + charNDArray result (dv, m_string_fill_char); single_type_concat<charNDArray> (result, tmp); @@ -2726,6 +2726,13 @@ return set_internal_variable (m_silent_functions, args, nargout, "silent_functions"); } + + octave_value + tree_evaluator::string_fill_char (const octave_value_list& args, int nargout) + { + return set_internal_variable (m_string_fill_char, args, nargout, + "string_fill_char"); + } } DEFMETHOD (max_recursion_depth, interp, args, nargout, @@ -2794,3 +2801,52 @@ %!error (silent_functions (1, 2)) */ + +DEFMETHOD (string_fill_char, interp, args, nargout, + doc: /* -*- texinfo -*- +@deftypefn {} {@var{val} =} string_fill_char () +@deftypefnx {} {@var{old_val} =} string_fill_char (@var{new_val}) +@deftypefnx {} {} string_fill_char (@var{new_val}, "local") +Query or set the internal variable used to pad all rows of a character +matrix to the same length. + +The value must be a single character and the default is @qcode{" "} (a +single space). For example: + +@example +@group +string_fill_char ("X"); +[ "these"; "are"; "strings" ] + @result{} "theseXX" + "areXXXX" + "strings" +@end group +@end example + +When called from inside a function with the @qcode{"local"} option, the +variable is changed locally for the function and any subroutines it calls. +The original variable value is restored when exiting the function. +@end deftypefn */) +{ + octave::tree_evaluator& tw = interp.get_evaluator (); + + return tw.string_fill_char (args, nargout); +} + +/* +## string_fill_char() function call must be outside of %!test block +## due to the way a %!test block is wrapped inside a function +%!shared orig_val, old_val +%! orig_val = string_fill_char (); +%! old_val = string_fill_char ("X"); +%!test +%! assert (orig_val, old_val); +%! assert (string_fill_char (), "X"); +%! assert (["these"; "are"; "strings"], ["theseXX"; "areXXXX"; "strings"]); +%! string_fill_char (orig_val); +%! assert (string_fill_char (), orig_val); + +%!assert ( [ [], {1} ], {1} ) + +%!error (string_fill_char (1, 2)) +*/
--- a/libinterp/parse-tree/pt-eval.h Mon Jun 26 23:54:43 2017 -0400 +++ b/libinterp/parse-tree/pt-eval.h Tue Jun 27 06:41:42 2017 -0400 @@ -106,7 +106,8 @@ tree_evaluator (interpreter& interp) : m_interpreter (interp), m_value_stack (), m_lvalue_list_stack (), m_nargout_stack (), m_call_stack (interp), - m_max_recursion_depth (256), m_silent_functions (false) + m_max_recursion_depth (256), m_silent_functions (false), + m_string_fill_char (' ') { } // No copying! @@ -321,6 +322,18 @@ octave_value silent_functions (const octave_value_list& args, int nargout); + char string_fill_char (void) const { return m_string_fill_char; } + + char string_fill_char (char c) + { + int val = m_string_fill_char; + m_string_fill_char = c; + return val; + } + + octave_value + string_fill_char (const octave_value_list& args, int nargout); + private: void do_breakpoint (tree_statement& stmt) const; @@ -357,6 +370,9 @@ // If TRUE, turn off printing of results in functions (as if a // semicolon has been appended to each statement). bool m_silent_functions; + + // The character to fill with when creating string arrays. + char m_string_fill_char; }; }
--- a/libinterp/parse-tree/pt-mat.cc Mon Jun 26 23:54:43 2017 -0400 +++ b/libinterp/parse-tree/pt-mat.cc Tue Jun 27 06:41:42 2017 -0400 @@ -38,9 +38,6 @@ #include "ov-re-sparse.h" #include "ov-cx-sparse.h" -// The character to fill with when creating string arrays. -char Vstring_fill_char = ' '; - namespace octave { std::string @@ -361,50 +358,3 @@ %!assert (isnull ([;,;])) %!assert (isnull ([,;,;,])) */ - -DEFUN (string_fill_char, args, nargout, - doc: /* -*- texinfo -*- -@deftypefn {} {@var{val} =} string_fill_char () -@deftypefnx {} {@var{old_val} =} string_fill_char (@var{new_val}) -@deftypefnx {} {} string_fill_char (@var{new_val}, "local") -Query or set the internal variable used to pad all rows of a character -matrix to the same length. - -The value must be a single character and the default is @qcode{" "} (a -single space). For example: - -@example -@group -string_fill_char ("X"); -[ "these"; "are"; "strings" ] - @result{} "theseXX" - "areXXXX" - "strings" -@end group -@end example - -When called from inside a function with the @qcode{"local"} option, the -variable is changed locally for the function and any subroutines it calls. -The original variable value is restored when exiting the function. -@end deftypefn */) -{ - return SET_INTERNAL_VARIABLE (string_fill_char); -} - -/* -## string_fill_char() function call must be outside of %!test block -## due to the way a %!test block is wrapped inside a function -%!shared orig_val, old_val -%! orig_val = string_fill_char (); -%! old_val = string_fill_char ("X"); -%!test -%! assert (orig_val, old_val); -%! assert (string_fill_char (), "X"); -%! assert (["these"; "are"; "strings"], ["theseXX"; "areXXXX"; "strings"]); -%! string_fill_char (orig_val); -%! assert (string_fill_char (), orig_val); - -%!assert ( [ [], {1} ], {1} ) - -%!error (string_fill_char (1, 2)) -*/
--- a/libinterp/parse-tree/pt-mat.h Mon Jun 26 23:54:43 2017 -0400 +++ b/libinterp/parse-tree/pt-mat.h Tue Jun 27 06:41:42 2017 -0400 @@ -36,9 +36,6 @@ #include "pt-walk.h" #include "symtab.h" -// The character to fill with when creating string arrays. -extern char Vstring_fill_char; - namespace octave { class tree_argument_list;