# HG changeset patch # User jwe # Date 1041607626 0 # Node ID 7cd865a8c815e26de2c7f45e3119f962ebac1eb6 # Parent 1086ac09a411a121599b9ae18faeda5410c210a0 [project @ 2003-01-03 15:27:05 by jwe] diff -r 1086ac09a411 -r 7cd865a8c815 src/ChangeLog --- a/src/ChangeLog Fri Jan 03 06:22:55 2003 +0000 +++ b/src/ChangeLog Fri Jan 03 15:27:06 2003 +0000 @@ -1,5 +1,23 @@ 2003-01-03 John W. Eaton + * pt-exp.h (tree_expression::has_magic_end): New pure virtual function. + * pt-id.h (tree_identifier::has_magic_end): New function. + * pt-colon.h (tree_colon_expression::has_magic_end): Likewise. + * pt-idx.h (tree_index_expression::has_magic_end): Likewise. + * pt-const.h (tree_constant::has_magic_end): Likewise. + * pt-unop.h (tree_unary_expression::has_magic_end): Likewise. + * pt-binop.h (tree_binary_expression::has_magic_end): Likewise. + * pt-assign.h (tree_multi_assignment::has_magic_end): Likewise. + (tree_simple_assignment::has_magic_end): Likewise. + * pt-mat.cc (tree_matrix::has_magic_end): Likewise. + * pt-arg-list.cc (tree_argument_list::has_magic_end): Likewise. + + * pt-arg-list.cc (tree_argument_list::append): Check all + expression types for magic end token.. + + * file-io.cc (Ftmpnam): Improve error checking. + (symbols_of_file_io): Move definition of P_tmpdir here from dirfns.cc. + * dirfns.cc (symbols_of_dirfns): Install new built-in constant P_tmpdir. diff -r 1086ac09a411 -r 7cd865a8c815 src/dirfns.cc --- a/src/dirfns.cc Fri Jan 03 06:22:55 2003 +0000 +++ b/src/dirfns.cc Fri Jan 03 15:27:06 2003 +0000 @@ -648,17 +648,6 @@ of this variable is system dependent.\n\ @end defvr"); -#if ! defined (P_tmpdir) -#define P_tmpdir "/tmp" -#endif - - DEFCONSTX ("P_tmpdir", SBV_P_tmpdir, P_tmpdir, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} P_tmpdir\n\ -The default name of the directory for temporary files on this system.\n\ -of this variable is system dependent.\n\ -@end defvr"); - } /* diff -r 1086ac09a411 -r 7cd865a8c815 src/file-io.cc --- a/src/file-io.cc Fri Jan 03 06:22:55 2003 +0000 +++ b/src/file-io.cc Fri Jan 03 15:27:06 2003 +0000 @@ -1477,12 +1477,15 @@ DEFUN (tmpnam, args, , "-*- texinfo -*-\n\ -@deftypefn {Built-in Function} {} tmpnam ()\n\ +@deftypefn {Built-in Function} {} tmpnam (@var{dir}, @var{prefix})\n\ Return a unique temporary file name as a string.\n\ \n\ -Since the named file is not opened, by @code{tmpnam}, it\n\ -is possible (though relatively unlikely) that it will not be available\n\ -by the time your program attempts to open it.\n\ +If @var{prefix} is omitted, a value of @code{\"oct-\"} is used.\n\ +If @var{dir} is also omitted, the default directory for temporary files\n\ +is used. If @var{dir} is provided, it must exist, otherwise the default\n\ +directory for temporary files is used. Since the named file is not\n\ +opened, by @code{tmpnam}, it is possible (though relatively unlikely)\n\ +that it will not be available by the time your program attempts to open it.\n\ @end deftypefn") { octave_value retval; @@ -1492,10 +1495,19 @@ if (len < 3) { std::string dir = len > 0 ? args(0).string_value () : std::string (); - std::string pfx = len > 1 ? args(1).string_value () : std::string ("oct-"); if (! error_state) - retval = file_ops::tempnam (dir, pfx); + { + std::string pfx + = len > 1 ? args(1).string_value () : std::string ("oct-"); + + if (! error_state) + retval = file_ops::tempnam (dir, pfx); + else + ::error ("expecting second argument to be a string"); + } + else + ::error ("expecting first argument to be a string"); } else print_usage ("tmpnam"); @@ -1584,6 +1596,17 @@ void symbols_of_file_io (void) { +#if ! defined (P_tmpdir) +#define P_tmpdir "/tmp" +#endif + + DEFCONSTX ("P_tmpdir", SBV_P_tmpdir, P_tmpdir, + "-*- texinfo -*-\n\ +@defvr {Built-in Variable} P_tmpdir\n\ +The default name of the directory for temporary files on this system.\n\ +of this variable is system dependent.\n\ +@end defvr"); + // NOTE: the values of SEEK_SET, SEEK_CUR, and SEEK_END have to be // this way for Matlab compatibility. diff -r 1086ac09a411 -r 7cd865a8c815 src/pt-arg-list.cc --- a/src/pt-arg-list.cc Fri Jan 03 06:22:55 2003 +0000 +++ b/src/pt-arg-list.cc Fri Jan 03 15:27:06 2003 +0000 @@ -57,19 +57,27 @@ } } +bool +tree_argument_list::has_magic_end (void) const +{ + for (const_iterator p = begin (); p != end (); p++) + { + tree_expression *elt = *p; + + if (elt && elt->has_magic_end ()) + return true; + } + + return false; +} + void tree_argument_list::append (const element_type& s) { octave_base_list::append (s); - // XXX FIXME XXX -- wait, it's not that simple! The argument list - // may include expressions, so we will have to do some more work - // here. We need a new function for all expression types that can - // tell us whether the expression includes the magic end token! - - // if (s && s->is_identifier () && s->name () == "__end__") - - list_includes_magic_end = true; + if (! list_includes_magic_end && s && s->has_magic_end ()) + list_includes_magic_end = true; } int diff -r 1086ac09a411 -r 7cd865a8c815 src/pt-arg-list.h --- a/src/pt-arg-list.h Fri Jan 03 06:22:55 2003 +0000 +++ b/src/pt-arg-list.h Fri Jan 03 15:27:06 2003 +0000 @@ -55,6 +55,8 @@ ~tree_argument_list (void); + bool has_magic_end (void) const; + tree_expression *remove_front (void) { iterator p = begin (); diff -r 1086ac09a411 -r 7cd865a8c815 src/pt-assign.h --- a/src/pt-assign.h Fri Jan 03 06:22:55 2003 +0000 +++ b/src/pt-assign.h Fri Jan 03 15:27:06 2003 +0000 @@ -59,6 +59,8 @@ ~tree_simple_assignment (void); + bool has_magic_end (void) const { return (rhs && rhs->has_magic_end ()); } + bool rvalue_ok (void) const { return true; } octave_value rvalue (void); @@ -125,6 +127,8 @@ ~tree_multi_assignment (void); + bool has_magic_end (void) const { return (rhs && rhs->has_magic_end ()); } + bool is_assignment_expression (void) const { return true; } bool rvalue_ok (void) const { return true; } diff -r 1086ac09a411 -r 7cd865a8c815 src/pt-binop.h --- a/src/pt-binop.h Fri Jan 03 06:22:55 2003 +0000 +++ b/src/pt-binop.h Fri Jan 03 15:27:06 2003 +0000 @@ -62,6 +62,12 @@ delete op_rhs; } + bool has_magic_end (void) const + { + return ((op_lhs && op_lhs->has_magic_end ()) + || (op_rhs && op_rhs->has_magic_end ())); + } + bool is_binary_expression (void) const { return true; } bool rvalue_ok (void) const { return true; } diff -r 1086ac09a411 -r 7cd865a8c815 src/pt-colon.h --- a/src/pt-colon.h Fri Jan 03 06:22:55 2003 +0000 +++ b/src/pt-colon.h Fri Jan 03 15:27:06 2003 +0000 @@ -61,6 +61,13 @@ delete op_increment; } + bool has_magic_end (void) const + { + return ((op_base && op_base->has_magic_end ()) + || (op_limit && op_limit->has_magic_end ()) + || (op_increment && op_increment->has_magic_end ())); + } + void preserve_base (void) { save_base = true; } tree_colon_expression *append (tree_expression *t); diff -r 1086ac09a411 -r 7cd865a8c815 src/pt-const.h --- a/src/pt-const.h Fri Jan 03 06:22:55 2003 +0000 +++ b/src/pt-const.h Fri Jan 03 15:27:06 2003 +0000 @@ -54,6 +54,8 @@ ~tree_constant (void) { } + bool has_magic_end (void) const { return false; } + void *operator new (size_t size) { return allocator.alloc (size); } void operator delete (void *p, size_t size) { allocator.free (p, size); } diff -r 1086ac09a411 -r 7cd865a8c815 src/pt-exp.h --- a/src/pt-exp.h Fri Jan 03 06:22:55 2003 +0000 +++ b/src/pt-exp.h Fri Jan 03 15:27:06 2003 +0000 @@ -47,6 +47,8 @@ virtual ~tree_expression (void) { } + virtual bool has_magic_end (void) const = 0; + virtual bool is_constant (void) const { return false; } virtual bool is_matrix_constant (void) const { return false; } diff -r 1086ac09a411 -r 7cd865a8c815 src/pt-id.h --- a/src/pt-id.h Fri Jan 03 06:22:55 2003 +0000 +++ b/src/pt-id.h Fri Jan 03 15:27:06 2003 +0000 @@ -56,6 +56,8 @@ ~tree_identifier (void) { } + bool has_magic_end (void) const { return (name () == "__end__"); } + bool is_identifier (void) const { return true; } std::string name (void) const; diff -r 1086ac09a411 -r 7cd865a8c815 src/pt-idx.h --- a/src/pt-idx.h Fri Jan 03 06:22:55 2003 +0000 +++ b/src/pt-idx.h Fri Jan 03 15:27:06 2003 +0000 @@ -60,6 +60,8 @@ ~tree_index_expression (void); + bool has_magic_end (void) const { return false; } + void append (tree_argument_list *lst = 0, char t = '('); void append (const std::string& n); diff -r 1086ac09a411 -r 7cd865a8c815 src/pt-mat.cc --- a/src/pt-mat.cc Fri Jan 03 06:22:55 2003 +0000 +++ b/src/pt-mat.cc Fri Jan 03 15:27:06 2003 +0000 @@ -409,6 +409,20 @@ } bool +tree_matrix::has_magic_end (void) const +{ + for (const_iterator p = begin (); p != end (); p++) + { + tree_argument_list *elt = *p; + + if (elt && elt->has_magic_end ()) + return true; + } + + return false; +} + +bool tree_matrix::all_elements_are_constant (void) const { for (const_iterator p = begin (); p != end (); p++) diff -r 1086ac09a411 -r 7cd865a8c815 src/pt-mat.h --- a/src/pt-mat.h Fri Jan 03 06:22:55 2003 +0000 +++ b/src/pt-mat.h Fri Jan 03 15:27:06 2003 +0000 @@ -56,6 +56,8 @@ ~tree_matrix (void); + bool has_magic_end (void) const; + bool all_elements_are_constant (void) const; bool rvalue_ok (void) const { return true; } diff -r 1086ac09a411 -r 7cd865a8c815 src/pt-unop.h --- a/src/pt-unop.h Fri Jan 03 06:22:55 2003 +0000 +++ b/src/pt-unop.h Fri Jan 03 15:27:06 2003 +0000 @@ -56,6 +56,8 @@ ~tree_unary_expression (void) { delete op; } + bool has_magic_end (void) const { return (op && op->has_magic_end ()); } + tree_expression *operand (void) { return op; } std::string oper (void) const;