Mercurial > hg > octave-terminal
changeset 4267:7cd865a8c815
[project @ 2003-01-03 15:27:05 by jwe]
author | jwe |
---|---|
date | Fri, 03 Jan 2003 15:27:06 +0000 |
parents | 1086ac09a411 |
children | 363d406ec86c |
files | src/ChangeLog src/dirfns.cc src/file-io.cc src/pt-arg-list.cc src/pt-arg-list.h src/pt-assign.h src/pt-binop.h src/pt-colon.h src/pt-const.h src/pt-exp.h src/pt-id.h src/pt-idx.h src/pt-mat.cc src/pt-mat.h src/pt-unop.h |
diffstat | 15 files changed, 108 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,23 @@ 2003-01-03 John W. Eaton <jwe@bevo.che.wisc.edu> + * 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.
--- a/src/dirfns.cc +++ b/src/dirfns.cc @@ -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"); - } /*
--- a/src/file-io.cc +++ b/src/file-io.cc @@ -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.
--- a/src/pt-arg-list.cc +++ b/src/pt-arg-list.cc @@ -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<tree_expression *>::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
--- a/src/pt-arg-list.h +++ b/src/pt-arg-list.h @@ -55,6 +55,8 @@ ~tree_argument_list (void); + bool has_magic_end (void) const; + tree_expression *remove_front (void) { iterator p = begin ();
--- a/src/pt-assign.h +++ b/src/pt-assign.h @@ -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; }
--- a/src/pt-binop.h +++ b/src/pt-binop.h @@ -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; }
--- a/src/pt-colon.h +++ b/src/pt-colon.h @@ -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);
--- a/src/pt-const.h +++ b/src/pt-const.h @@ -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); }
--- a/src/pt-exp.h +++ b/src/pt-exp.h @@ -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; }
--- a/src/pt-id.h +++ b/src/pt-id.h @@ -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;
--- a/src/pt-idx.h +++ b/src/pt-idx.h @@ -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);
--- a/src/pt-mat.cc +++ b/src/pt-mat.cc @@ -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++)